From 924ef3891cad9f99462d010feed19b14bdcd32f5 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 13:44:51 +0900 Subject: [PATCH] fix(bootstrap): keep unvalidated config values out of the safe boot error (Q-6.9-10) On CONFIG_SCHEMA_INVALID the loader copied the raw RELEASE_ID and CONFIG_SCHEMA_VERSION strings (up to the 64 KB body limit) into the "safe" error that BootErrorShell and diagnostics show, contradicting the file's own contract. The error now carries the schema version only when it passed the version gate (no validator issue at CONFIG_SCHEMA_VERSION) and never the release id of a rejected document. Verified: two cases in tests/runtime-schema/runtime-config.test.ts (invalid field with a 10 KB RELEASE_ID; unsupported 10 KB version) RED before, green after; test:runtime-schema and all gates PASS. Co-Authored-By: Claude Opus 5.5 --- src/bootstrap/load-runtime-config.ts | 12 +++--- tests/runtime-schema/runtime-config.test.ts | 42 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/bootstrap/load-runtime-config.ts b/src/bootstrap/load-runtime-config.ts index 5cd5f40f..9cfc3a36 100644 --- a/src/bootstrap/load-runtime-config.ts +++ b/src/bootstrap/load-runtime-config.ts @@ -116,16 +116,18 @@ export async function loadRuntimeConfig( const validated = validateRuntimeConfig(rawConfig); if (!validated.success) { + // Q-6.9-10. Only a value that passed a check reaches the safe error. The + // declared schema version did when it selected a parser; nothing else in + // a rejected document did (RELEASE_ID could be 64 KB of anything). + const versionAccepted = !validated.issues.some( + (issue) => issue.path === "CONFIG_SCHEMA_VERSION", + ); throw new BootConfigError("CONFIG_SCHEMA_INVALID", { buildId: buildConfig.buildId, configSchemaVersion: - typeof rawConfig.CONFIG_SCHEMA_VERSION === "string" + versionAccepted && typeof rawConfig.CONFIG_SCHEMA_VERSION === "string" ? rawConfig.CONFIG_SCHEMA_VERSION : undefined, - releaseId: - typeof rawConfig.RELEASE_ID === "string" - ? rawConfig.RELEASE_ID - : undefined, }); } diff --git a/tests/runtime-schema/runtime-config.test.ts b/tests/runtime-schema/runtime-config.test.ts index c277ace9..b7b71af0 100644 --- a/tests/runtime-schema/runtime-config.test.ts +++ b/tests/runtime-schema/runtime-config.test.ts @@ -1,6 +1,9 @@ import { describe, expect, it } from "vitest"; -import { loadRuntimeConfig } from "../../src/bootstrap/load-runtime-config.ts"; +import { + BootConfigError, + loadRuntimeConfig, +} from "../../src/bootstrap/load-runtime-config.ts"; import { validateRuntimeConfig } from "../../src/bootstrap/runtime-config-schema.ts"; import { assertSafeConfigNames } from "../../src/contracts/env.ts"; @@ -228,6 +231,43 @@ describe("runtime configuration boundary", () => { expect(result.validationDurationMs).toBe(0); }); + it.each([ + [ + "an invalid field", + { ...validConfig, REQUEST_TIMEOUT_MS: -1, RELEASE_ID: "r".repeat(10_000) }, + { configSchemaVersion: "2.0" }, + ], + [ + "an unsupported version", + { ...validConfig, CONFIG_SCHEMA_VERSION: "v".repeat(10_000), RELEASE_ID: "release-a" }, + {}, + ], + ])( + "puts only validated config values into the safe error for %s (Q-6.9-10)", + async (_case, document, expected) => { + const failure = await loadRuntimeConfig({ + buildConfig: { + buildId: "build-a", + commitSha: "local", + routerBasePath: "/", + runtimeConfigUrl: "/config.json", + }, + fetcher: async () => + new Response(JSON.stringify(document), { + headers: { "content-type": "application/json" }, + }), + }).catch((error: unknown) => error); + + expect(failure).toBeInstanceOf(BootConfigError); + const safe = (failure as BootConfigError).safe; + expect(safe.code).toBe("CONFIG_SCHEMA_INVALID"); + expect({ + configSchemaVersion: safe.configSchemaVersion, + releaseId: safe.releaseId, + }).toEqual({ configSchemaVersion: undefined, releaseId: undefined, ...expected }); + }, + ); + it("returns only safe boot fields on failure", async () => { await expect( loadRuntimeConfig({