diff --git a/src/contracts/release-artifacts.ts b/src/contracts/release-artifacts.ts index 7cd038cc..6dcd23aa 100644 --- a/src/contracts/release-artifacts.ts +++ b/src/contracts/release-artifacts.ts @@ -32,9 +32,19 @@ export function isValidReleaseManifestUrl(value: string): boolean { return false; } if (/%2f|%5c/i.test(value)) return false; - return !value - .split("/") - .some((segment) => segment === "." || segment === ".."); + if (value.split("/").some((segment) => segment === "." || segment === "..")) { + return false; + } + // R-7.3. The URL parser strips tab/CR/LF and resolves `%2e` dot segments, so + // "/\t/evil.example/m.json" becomes a cross-origin URL. The path must + // resolve to exactly itself on the page's origin. + const base = "https://release-manifest.invalid"; + try { + const resolved = new URL(value, base); + return resolved.origin === base && resolved.pathname === value; + } catch { + return false; + } } export const capabilityOverrideArtifactSchema = z diff --git a/tests/runtime-schema/runtime-config.test.ts b/tests/runtime-schema/runtime-config.test.ts index 1988a9a8..c277ace9 100644 --- a/tests/runtime-schema/runtime-config.test.ts +++ b/tests/runtime-schema/runtime-config.test.ts @@ -53,12 +53,37 @@ describe("runtime configuration boundary", () => { { ...validConfig, RELEASE_MANIFEST_URL: "/manifest.json?v=1" }, "ยง6.2 query in manifest URL", ], + [ + { ...validConfig, RELEASE_MANIFEST_URL: "/\t/evil.example/m.json" }, + "R-7.3 tab turns the path into a protocol-relative URL", + ], + [ + { ...validConfig, RELEASE_MANIFEST_URL: "/\n/evil.example/m.json" }, + "R-7.3 newline is stripped by the URL parser", + ], + [ + { ...validConfig, RELEASE_MANIFEST_URL: "/a/%2e%2e/b.json" }, + "R-7.3 encoded dot segment", + ], + [ + { ...validConfig, RELEASE_MANIFEST_URL: "/a/%2E/b.json" }, + "R-7.3 encoded single dot segment", + ], [{ ...validConfig, UNKNOWN_KEY: true }, "unknown key"], ])("rejects invalid config: %s (%s)", (candidate, _reason) => { void _reason; expect(validateRuntimeConfig(candidate).success).toBe(false); }); + it.each(["/release-manifest.json", "/app/v1/release-manifest.json", "/a/.well-known/m.json"])( + "accepts a same-origin manifest path: %s", + (RELEASE_MANIFEST_URL) => { + expect( + validateRuntimeConfig({ ...validConfig, RELEASE_MANIFEST_URL }).success, + ).toBe(true); + }, + ); + it("rejects secret-like names before schema validation", () => { expect(() => assertSafeConfigNames({ CLIENT_SECRET: "not-safe" })).toThrow( "Forbidden client configuration key",