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 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 13:58:35 +09:00
co-authored by Claude Opus 5.5
parent 40659de7ec
commit 924ef3891c
2 changed files with 48 additions and 6 deletions
+7 -5
View File
@@ -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,
});
}
+41 -1
View File
@@ -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({