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 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 12:19:48 +09:00
co-authored by Claude Opus 5.5
parent 4f7a3be50d
commit 691cf37486
2 changed files with 57 additions and 2 deletions
+19 -2
View File
@@ -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<string, unknown>, 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<string, unknown> {
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) =>
@@ -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, unknown>, 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,