From abb3df7e35197733f38dc4866c8a0d98f50b00d8 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:45:38 +1100 Subject: [PATCH] fix(site): avoid constructing invalid apps url (#15711) In Firefox, parsing a URL containing a `*` returns an error: ``` new URL("https://*--apps.sydney.fly.dev.coder.com") ``` ``` Uncaught TypeError: URL constructor: https://*--apps.sydney.fly.dev.coder.com is not a valid URL. debugger eval code:1 ``` In Chrome and Node, this same URL does not produce an error. This causes a workspace dashboard with apps to fail to load on Firefox. ![image](https://github.com/user-attachments/assets/eeea4fe5-3759-432b-b7ce-22dfad5f8218) --- site/src/utils/apps.ts | 3 +-- site/src/utils/portForward.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/site/src/utils/apps.ts b/site/src/utils/apps.ts index 29dd275acf..fcb1d42805 100644 --- a/site/src/utils/apps.ts +++ b/site/src/utils/apps.ts @@ -29,9 +29,8 @@ export const createAppLinkHref = ( } if (appsHost && app.subdomain && app.subdomain_name) { - const baseUrl = `${protocol}//${appsHost}`; + const baseUrl = `${protocol}//${appsHost.replace("*", app.subdomain_name)}`; const url = new URL(baseUrl); - url.hostname = appsHost.replace("*", app.subdomain_name); url.pathname = "/"; href = url.toString(); diff --git a/site/src/utils/portForward.ts b/site/src/utils/portForward.ts index 97f7628b5e..e9e5a81d39 100644 --- a/site/src/utils/portForward.ts +++ b/site/src/utils/portForward.ts @@ -13,9 +13,8 @@ export const portForwardURL = ( const subdomain = `${port}${suffix}--${agentName}--${workspaceName}--${username}`; - const baseUrl = `${location.protocol}//${host}`; + const baseUrl = `${location.protocol}//${host.replace("*", subdomain)}`; const url = new URL(baseUrl); - url.hostname = host.replace("*", subdomain); return url.toString(); };