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
@@ -37,6 +37,7 @@ import {
|
||||
signRelayJwt,
|
||||
verifyRelayJwt,
|
||||
} from "@t3tools/shared/relayJwt";
|
||||
import { isSecureRelayUrl } from "@t3tools/shared/relayUrl";
|
||||
import * as DateTime from "effect/DateTime";
|
||||
import * as Crypto from "effect/Crypto";
|
||||
import * as Duration from "effect/Duration";
|
||||
@@ -155,20 +156,6 @@ function validateCloudMintPublicKey(
|
||||
);
|
||||
}
|
||||
|
||||
function isSecureRelayUrl(value: string): boolean {
|
||||
try {
|
||||
const url = new URL(value);
|
||||
return (
|
||||
url.protocol === "https:" &&
|
||||
url.username.length === 0 &&
|
||||
url.password.length === 0 &&
|
||||
url.hash.length === 0
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function validateRelayConfigPayload(
|
||||
payload: RelayEnvironmentConfigRequest,
|
||||
): Effect.Effect<void, EnvironmentHttpBadRequestError> {
|
||||
|
||||
@@ -2127,6 +2127,11 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
relayIssuer: "http://relay.example.test",
|
||||
environmentCredential: "t3env_test_credential",
|
||||
});
|
||||
const nonOriginRelayUrl = yield* postRelayConfig({
|
||||
relayUrl: "https://relay.example.test/path",
|
||||
cloudUserId: "user_123",
|
||||
environmentCredential: "t3env_test_credential",
|
||||
});
|
||||
const emptyCredential = yield* postRelayConfig({
|
||||
relayUrl: "https://relay.example.test",
|
||||
cloudUserId: "user_123",
|
||||
@@ -2138,6 +2143,9 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
const insecureRelayIssuerBody = yield* responseJsonEffect<{ readonly message?: string }>(
|
||||
insecureRelayIssuer,
|
||||
);
|
||||
const nonOriginRelayUrlBody = yield* responseJsonEffect<{ readonly message?: string }>(
|
||||
nonOriginRelayUrl,
|
||||
);
|
||||
const emptyCredentialBody = yield* responseJsonEffect<{ readonly message?: string }>(
|
||||
emptyCredential,
|
||||
);
|
||||
@@ -2149,6 +2157,8 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
insecureRelayIssuerBody.message,
|
||||
"Relay issuer must be a secure absolute HTTPS URL.",
|
||||
);
|
||||
assert.equal(nonOriginRelayUrl.status, 400);
|
||||
assert.equal(nonOriginRelayUrlBody.message, "Relay URL must be a secure absolute HTTPS URL.");
|
||||
assert.equal(emptyCredential.status, 400);
|
||||
assert.equal(emptyCredentialBody.message, "Relay environment credential is required.");
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
|
||||
Reference in new issue
Block a user