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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
691cf37486
commit
b31daab324
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user