| ... | @@ -24,6 +24,11 @@ const isPrivateNetworkHost = (host: string): boolean => { | ... | @@ -24,6 +24,11 @@ const isPrivateNetworkHost = (host: string): boolean => { |
| 24 | ); | 24 | ); |
| 25 | }; | 25 | }; |
| 26 | | 26 | |
| | 27 | const isLocalLoopbackHost = (host: string): boolean => { |
| | 28 | const normalized = host.toLowerCase().replace(/^\[|\]$/g, ""); |
| | 29 | return normalized === "localhost" || normalized === "127.0.0.1" || normalized === "::1"; |
| | 30 | }; |
| | 31 | |
| 27 | export function resolveBrowserNavigationTarget( | 32 | export function resolveBrowserNavigationTarget( |
| 28 | environmentId: EnvironmentId, | 33 | environmentId: EnvironmentId, |
| 29 | target: BrowserNavigationTarget, | 34 | target: BrowserNavigationTarget, |
| ... | @@ -68,6 +73,12 @@ export function resolveDiscoveredServerUrl(environmentId: EnvironmentId, rawUrl: | ... | @@ -68,6 +73,12 @@ export function resolveDiscoveredServerUrl(environmentId: EnvironmentId, rawUrl: |
| 68 | const normalizedUrl = normalizePreviewUrl(rawUrl); | 73 | const normalizedUrl = normalizePreviewUrl(rawUrl); |
| 69 | const parsed = new URL(normalizedUrl); | 74 | const parsed = new URL(normalizedUrl); |
| 70 | if (!isLoopbackHost(parsed.hostname)) return normalizedUrl; | 75 | if (!isLoopbackHost(parsed.hostname)) return normalizedUrl; |
| | 76 | const connection = readPreparedConnection(environmentId); |
| | 77 | if (!connection) throw new Error(`Environment ${environmentId} is not connected.`); |
| | 78 | const environmentUrl = new URL(connection.httpBaseUrl); |
| | 79 | if (parsed.hostname !== "0.0.0.0" && isLocalLoopbackHost(environmentUrl.hostname)) { |
| | 80 | return normalizedUrl; |
| | 81 | } |
| 71 | const port = Number(parsed.port || (parsed.protocol === "https:" ? 443 : 80)); | 82 | const port = Number(parsed.port || (parsed.protocol === "https:" ? 443 : 80)); |
| 72 | return resolveBrowserNavigationTarget(environmentId, { | 83 | return resolveBrowserNavigationTarget(environmentId, { |
| 73 | kind: "environment-port", | 84 | kind: "environment-port", |