fix(relay): use TLS for any port-443 relay endpoint (#774)

* fix(relay): use TLS for any port-443 relay endpoint

`shouldUseTlsForDefaultHostedRelay` only returned true for
`relay.paseo.sh:443`. Self-hosted relays on port 443 connected via
`ws://` instead of `wss://`, causing HTTP 400 from the TLS server.

Port-based detection: port 443 → wss, everything else → ws.

* Test port-based hosted relay TLS detection

Cover the new behavior: any port-443 endpoint (hosted Paseo or
self-hosted) and IPv6 hosts return true, non-443 ports and malformed
input return false.

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
Zitao Xiong
2026-05-06 19:56:32 +08:00
committed by GitHub
co-authored by Mohamed Boudra
parent 7e8187ddc7
commit 24bdd3c8ad
2 changed files with 25 additions and 1 deletions
@@ -9,6 +9,7 @@ import {
parseConnectionUri,
serializeConnectionUri,
serializeConnectionUriForStorage,
shouldUseTlsForDefaultHostedRelay,
} from "./daemon-endpoints.js";
describe("connection URI parsing", () => {
@@ -188,3 +189,25 @@ describe("relay websocket URLs", () => {
expect(extractHostPortFromWebSocketUrl(wsUrl)).toBe("[::1]:443");
});
});
describe("shouldUseTlsForDefaultHostedRelay", () => {
test("returns true for the hosted Paseo relay on port 443", () => {
expect(shouldUseTlsForDefaultHostedRelay("relay.paseo.sh:443")).toBe(true);
});
test("returns true for any self-hosted relay on port 443", () => {
expect(shouldUseTlsForDefaultHostedRelay("relay.example.com:443")).toBe(true);
});
test("returns true for an IPv6 relay on port 443", () => {
expect(shouldUseTlsForDefaultHostedRelay("[::1]:443")).toBe(true);
});
test("returns false for a relay on a non-443 port", () => {
expect(shouldUseTlsForDefaultHostedRelay("relay.example.com:8080")).toBe(false);
});
test("returns false for malformed endpoints", () => {
expect(shouldUseTlsForDefaultHostedRelay("not-an-endpoint")).toBe(false);
});
});
@@ -204,7 +204,8 @@ export function buildRelayWebSocketUrl(params: {
*/
export function shouldUseTlsForDefaultHostedRelay(endpoint: string): boolean {
try {
return normalizeHostPort(endpoint) === DEFAULT_RELAY_ENDPOINT;
const { port } = parseHostPort(endpoint);
return port === 443;
} catch {
return false;
}