fix(cloud): validate relay URL origins

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-06-04 14:03:01 -07:00
1 parent 26f36ca992
commit 7b3bc331cc
11 files changed
+144 -26

No files matched your search

@@ -31,4 +31,17 @@ describe("resolveCloudPublicConfig", () => {
relayUrl: "https://relay.example.test",
});
});
it("rejects an insecure relay URL", () => {
expect(
resolveCloudPublicConfig({
clerk: { publishableKey: "pk_test_example", jwtTemplate: "t3-relay" },
relay: { url: "http://relay.example.test" },
}),
).toEqual({
clerkPublishableKey: "pk_test_example",
clerkJwtTemplate: "t3-relay",
relayUrl: null,
});
});
});
@@ -1,5 +1,6 @@
import Constants from "expo-constants";
import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
type ExpoExtra = Readonly<Record<string, unknown>> | undefined;
@@ -22,7 +23,7 @@ export function resolveCloudPublicConfig(extra: ExpoExtra = Constants.expoConfig
return {
clerkPublishableKey: trimNonEmpty(clerk?.publishableKey),
clerkJwtTemplate: trimNonEmpty(clerk?.jwtTemplate),
relayUrl: trimNonEmpty(relay?.url)?.replace(/\/+$/u, "") ?? null,
relayUrl: normalizeSecureRelayUrl(trimNonEmpty(relay?.url) ?? ""),
} satisfies CloudPublicConfig;
}