Skip to content

Commit 69e5ad8

Browse files
authored
fix(web): treat configured urls with uppercase schemes as secure (pingdotgg#8005)
Co-authored-by: Simone <[email protected]>
1 parent a9cd94e commit 69e5ad8

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎apps/web/src/environments/primary/bootstrap.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ describe("environmentBootstrap", () => {
155155
});
156156
});
157157

158+
it("keeps an uppercase wss scheme secure when deriving the http url", () => {
159+
vi.stubEnv("VITE_WS_URL", "WSS://remote.example.com");
160+
161+
expect(readPrimaryEnvironmentTarget().target).toEqual({
162+
httpBaseUrl: "https://remote.example.com/",
163+
wsBaseUrl: "wss://remote.example.com/",
164+
});
165+
});
166+
167+
it("keeps an uppercase https scheme secure when deriving the websocket url", () => {
168+
vi.stubEnv("VITE_HTTP_URL", "HTTPS://remote.example.com");
169+
170+
expect(readPrimaryEnvironmentTarget().target).toEqual({
171+
httpBaseUrl: "https://remote.example.com/",
172+
wsBaseUrl: "wss://remote.example.com/",
173+
});
174+
});
175+
158176
it("uses the current origin as the descriptor base for local dev environments", async () => {
159177
installTestBrowser("http://localhost:5735/");
160178
await installDescriptorApi();

‎apps/web/src/environments/primary/target.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,18 @@ function resolveConfiguredPrimaryTarget(): PrimaryEnvironmentTarget | null {
189189
return null;
190190
}
191191

192+
// Scheme checks run on the raw configured string, while the URL parser
193+
// folds schemes to lowercase ("WSS://host" parses fine). Without the
194+
// case folding an uppercase scheme would be classified as plaintext and
195+
// swapped to http/ws, silently downgrading TLS.
192196
const resolvedHttpBaseUrl =
193197
configuredHttpBaseUrl ??
194-
(configuredWsBaseUrl?.startsWith("wss:")
198+
(configuredWsBaseUrl?.toLowerCase().startsWith("wss:")
195199
? swapBaseUrlProtocol(configuredWsBaseUrl, "https:", "websocket-base-url")
196200
: swapBaseUrlProtocol(configuredWsBaseUrl!, "http:", "websocket-base-url"));
197201
const resolvedWsBaseUrl =
198202
configuredWsBaseUrl ??
199-
(configuredHttpBaseUrl?.startsWith("https:")
203+
(configuredHttpBaseUrl?.toLowerCase().startsWith("https:")
200204
? swapBaseUrlProtocol(configuredHttpBaseUrl, "wss:", "http-base-url")
201205
: swapBaseUrlProtocol(configuredHttpBaseUrl!, "ws:", "http-base-url"));
202206

0 commit comments

Comments
 (0)