From b31daab324e7d06ec62612abbef741d8a79437d4 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 12:05:25 +0900 Subject: [PATCH] fix(contracts): require the release manifest path to resolve to itself (R-7.3) isValidReleaseManifestUrl only rejected `//`, `?`, `#`, `\`, `%2f`/`%5c` and literal dot segments. The WHATWG URL parser strips tab/CR/LF and resolves `%2e` dot segments, so "/\t/evil.example/m.json" resolved to https://evil.example/m.json and "/a/%2e%2e/b.json" to "/b.json". The value is now also resolved against a fixed base and must keep that origin and have a pathname identical to the input. RED: "runtime configuration boundary > rejects invalid config" cases for a tab, a newline, "/a/%2e%2e/b.json" and "/a/%2E/b.json" failed (validation succeeded) before the fix. Added accept cases for normal same-origin paths. Gates: check:architecture, check:types:app/test/node, lint, test:component, test:runtime-schema, test:contract pass; test:unit passes except the environment-dependent removal-fixture.test.ts (needs generated artifacts/release files; unrelated). tests/release, tests/platform/release and tests/integration also pass. Co-Authored-By: Claude Opus 5.5 --- src/contracts/release-artifacts.ts | 16 ++++++++++--- tests/runtime-schema/runtime-config.test.ts | 25 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) 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",