From 691cf374863318f0e3ad2ef435adb0a98e878a3f Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 12:02:20 +0900 Subject: [PATCH] fix(contracts): exempt FEATURE_OVERRIDES feature ids from secret-name check (R-7.2) assertSafeConfigNames recursed into every nested object, so the feature ids that key FEATURE_OVERRIDES were checked as configuration names. The feature-id grammar allows `cookie-consent`, `password-reset` and `token-wallet`, so using the runtime kill switch for such a feature made loadRuntimeConfig throw CONFIG_SECRET_NAME_REJECTED and the app failed to boot. The keys of FEATURE_OVERRIDES (exact top-level key only) are now skipped; objects nested below a feature id, other nested maps and the top level are still checked. RED: "runtime configuration boundary > loads a config whose FEATURE_OVERRIDES name a secret-looking feature id" failed with BootConfigError CONFIG_SECRET_NAME_REJECTED before the fix. Added cases that forbidden names at top level, in CAPABILITY_OVERRIDES, deeper nesting and below a feature id are still rejected. 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). Co-Authored-By: Claude Opus 5.5 --- src/contracts/env.ts | 21 ++++++++++-- tests/runtime-schema/runtime-config.test.ts | 38 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/contracts/env.ts b/src/contracts/env.ts index 5c00a618..c5b20beb 100644 --- a/src/contracts/env.ts +++ b/src/contracts/env.ts @@ -23,6 +23,14 @@ const SEMANTIC_KEY_ALLOWLIST = Object.freeze( new Set(["AUTH_MODE", "TELEMETRY_ENABLED"]), ); +/** + * R-7.2. Exact top-level keys whose own keys are feature ids (data), not + * configuration names: `cookie-consent` or `token-wallet` is a feature, not a + * credential. Only the map keys are exempt; anything nested below them is + * still checked. + */ +const FEATURE_ID_KEYED_MAPS = Object.freeze(new Set(["FEATURE_OVERRIDES"])); + export type EnvironmentPhase = "build" | "runtime"; export type EnvironmentDefinition = Readonly<{ phase: EnvironmentPhase; @@ -82,12 +90,21 @@ export function assertSafeConfigNames( if (!allowlisted && isForbiddenConfigName(name)) { throw new Error(`Forbidden client configuration key: ${name}`); } - if (value && typeof value === "object" && !Array.isArray(value)) { - assertSafeConfigNames(value as Record, depth + 1); + if (!isPlainNested(value)) continue; + if (depth === 0 && FEATURE_ID_KEYED_MAPS.has(name)) { + for (const entry of Object.values(value)) { + if (isPlainNested(entry)) assertSafeConfigNames(entry, depth + 2); + } + } else { + assertSafeConfigNames(value, depth + 1); } } } +function isPlainNested(value: unknown): value is Record { + return Boolean(value) && typeof value === "object" && !Array.isArray(value); +} + function isForbiddenConfigName(name: string): boolean { const upper = name.toUpperCase(); return FORBIDDEN_CONFIG_NAME_FRAGMENTS.some((fragment) => diff --git a/tests/runtime-schema/runtime-config.test.ts b/tests/runtime-schema/runtime-config.test.ts index c3090a09..1988a9a8 100644 --- a/tests/runtime-schema/runtime-config.test.ts +++ b/tests/runtime-schema/runtime-config.test.ts @@ -65,6 +65,44 @@ describe("runtime configuration boundary", () => { ); }); + // R-7.2. FEATURE_OVERRIDES keys are feature ids (data), not configuration + // names; a kill switch for `cookie-consent` must not fail boot. + it("loads a config whose FEATURE_OVERRIDES name a secret-looking feature id", async () => { + const result = await loadRuntimeConfig({ + buildConfig: { + buildId: "build-a", + commitSha: "local", + routerBasePath: "/", + runtimeConfigUrl: "/config.json", + }, + fetcher: async () => + new Response( + JSON.stringify({ + ...validConfig, + FEATURE_OVERRIDES: { + "cookie-consent": "DISABLED", + "password-reset": "DISABLED", + "token-wallet": "DEFAULT", + }, + }), + { headers: { "content-type": "application/json" } }, + ), + }); + + expect(result.config.FEATURE_OVERRIDES["cookie-consent"]).toBe("DISABLED"); + }); + + it.each<[Record, string]>([ + [{ FEATURE_OVERRIDES: {}, CLIENT_SECRET: "x" }, "top level"], + [{ CAPABILITY_OVERRIDES: { AUTH_TOKEN: "DEFAULT" } }, "other nested map"], + [{ NESTED: { deeper: { PRIVATE_KEY: "x" } } }, "deeper nesting"], + [{ FEATURE_OVERRIDES: { alpha: { CLIENT_SECRET: "x" } } }, "below a feature id"], + ])("still rejects forbidden names outside feature ids: %o (%s)", (candidate) => { + expect(() => assertSafeConfigNames(candidate)).toThrow( + "Forbidden client configuration key", + ); + }); + it("allows demo authentication only for local runtime configuration", () => { expect( validateRuntimeConfig({ ...validConfig, AUTH_MODE: "demo" }).success,