fix(web): treat configured urls with uppercase schemes as secure (#8005)
Co-authored-by: Simone <[email protected]>
This commit is contained in:
1 parent
a9cd94eb93
commit
69e5ad8846
2 files changed
+24
-2
No files matched your search
@@ -155,6 +155,24 @@ describe("environmentBootstrap", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps an uppercase wss scheme secure when deriving the http url", () => {
|
||||
vi.stubEnv("VITE_WS_URL", "WSS://remote.example.com");
|
||||
|
||||
expect(readPrimaryEnvironmentTarget().target).toEqual({
|
||||
httpBaseUrl: "https://remote.example.com/",
|
||||
wsBaseUrl: "wss://remote.example.com/",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps an uppercase https scheme secure when deriving the websocket url", () => {
|
||||
vi.stubEnv("VITE_HTTP_URL", "HTTPS://remote.example.com");
|
||||
|
||||
expect(readPrimaryEnvironmentTarget().target).toEqual({
|
||||
httpBaseUrl: "https://remote.example.com/",
|
||||
wsBaseUrl: "wss://remote.example.com/",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the current origin as the descriptor base for local dev environments", async () => {
|
||||
installTestBrowser("http://localhost:5735/");
|
||||
await installDescriptorApi();
|
||||
|
||||
@@ -189,14 +189,18 @@ function resolveConfiguredPrimaryTarget(): PrimaryEnvironmentTarget | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Scheme checks run on the raw configured string, while the URL parser
|
||||
// folds schemes to lowercase ("WSS://host" parses fine). Without the
|
||||
// case folding an uppercase scheme would be classified as plaintext and
|
||||
// swapped to http/ws, silently downgrading TLS.
|
||||
const resolvedHttpBaseUrl =
|
||||
configuredHttpBaseUrl ??
|
||||
(configuredWsBaseUrl?.startsWith("wss:")
|
||||
(configuredWsBaseUrl?.toLowerCase().startsWith("wss:")
|
||||
? swapBaseUrlProtocol(configuredWsBaseUrl, "https:", "websocket-base-url")
|
||||
: swapBaseUrlProtocol(configuredWsBaseUrl!, "http:", "websocket-base-url"));
|
||||
const resolvedWsBaseUrl =
|
||||
configuredWsBaseUrl ??
|
||||
(configuredHttpBaseUrl?.startsWith("https:")
|
||||
(configuredHttpBaseUrl?.toLowerCase().startsWith("https:")
|
||||
? swapBaseUrlProtocol(configuredHttpBaseUrl, "wss:", "http-base-url")
|
||||
: swapBaseUrlProtocol(configuredHttpBaseUrl!, "ws:", "http-base-url"));
|
||||
|
||||
|
||||
Reference in new issue
Block a user