fix(cloud): validate relay URL origins
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
26f36ca992
commit
7b3bc331cc
11 files changed
+144
-26
No files matched your search
@@ -22,4 +22,12 @@ describe("hasCloudPublicConfig", () => {
|
||||
vi.stubEnv("VITE_T3CODE_RELAY_URL", "https://relay.example.test");
|
||||
expect(hasCloudPublicConfig()).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects an insecure relay URL", () => {
|
||||
vi.stubEnv("VITE_CLERK_PUBLISHABLE_KEY", "pk_test_example");
|
||||
vi.stubEnv("VITE_CLERK_JWT_TEMPLATE", "t3-relay");
|
||||
vi.stubEnv("VITE_T3CODE_RELAY_URL", "http://relay.example.test");
|
||||
|
||||
expect(hasCloudPublicConfig()).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
|
||||
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
|
||||
|
||||
export interface CloudPublicConfig {
|
||||
readonly clerkPublishableKey: string | null;
|
||||
@@ -16,11 +17,9 @@ export function resolveCloudPublicConfig(): CloudPublicConfig {
|
||||
import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string | undefined,
|
||||
),
|
||||
clerkJwtTemplate: trimNonEmpty(import.meta.env.VITE_CLERK_JWT_TEMPLATE as string | undefined),
|
||||
relayUrl:
|
||||
trimNonEmpty(import.meta.env.VITE_T3CODE_RELAY_URL as string | undefined)?.replace(
|
||||
/\/+$/u,
|
||||
"",
|
||||
) ?? null,
|
||||
relayUrl: normalizeSecureRelayUrl(
|
||||
(import.meta.env.VITE_T3CODE_RELAY_URL as string | undefined) ?? "",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user