Skip to content

Commit 45ed68e

Browse files
authored
fix(release): accept trusted Codex scan layouts (#126588)
Allow the trusted release inventory to accept exactly one complete reviewed Codex source layout while remaining fail closed for partial, mixed, duplicate, absent, or unknown layouts. Frozen-candidate and upstream Codex contract proof are recorded in the PR.
1 parent 1d2986b commit 45ed68e

1 file changed

Lines changed: 123 additions & 10 deletions

File tree

‎src/plugins/npm-install-security-scan.release.test.ts‎

Lines changed: 123 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const execFileAsync = promisify(execFile);
2727
const REQUIRED_REVIEWED_PUBLISHABLE_CRITICAL_FINDING_COUNTS = new Map<string, number>([
2828
["@openclaw/acpx:dangerous-exec:src/codex-auth-bridge.ts", 1],
2929
["@openclaw/acpx:dangerous-exec:src/runtime-internals/mcp-proxy.mjs", 1],
30-
["@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/sandbox-child.ts", 1],
31-
["@openclaw/codex:dangerous-exec:src/app-server/transport-process-containment.ts", 1],
3230
["@openclaw/codex:dangerous-exec:src/app-server/transport-stdio.ts", 1],
3331
["@openclaw/codex:dangerous-exec:src/doctor.ts", 1],
3432
["@openclaw/codex:dangerous-exec:src/node-cli-sessions.ts", 1],
@@ -42,6 +40,22 @@ const REQUIRED_REVIEWED_PUBLISHABLE_CRITICAL_FINDING_COUNTS = new Map<string, nu
4240
["@openclaw/voice-call:dangerous-exec:src/tunnel.ts", 1],
4341
]);
4442

43+
const REVIEWED_CODEX_LEGACY_SOURCE_CRITICAL_FINDING_COUNTS = new Map<string, number>([
44+
["@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/http.ts", 1],
45+
["@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/processes.ts", 1],
46+
]);
47+
const REVIEWED_CODEX_CURRENT_SOURCE_CRITICAL_FINDING_COUNTS = new Map<string, number>([
48+
["@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/sandbox-child.ts", 1],
49+
["@openclaw/codex:dangerous-exec:src/app-server/transport-process-containment.ts", 1],
50+
]);
51+
const REVIEWED_CODEX_SOURCE_LAYOUTS: ReadonlyArray<ReadonlyMap<string, number>> = [
52+
REVIEWED_CODEX_LEGACY_SOURCE_CRITICAL_FINDING_COUNTS,
53+
REVIEWED_CODEX_CURRENT_SOURCE_CRITICAL_FINDING_COUNTS,
54+
];
55+
const REVIEWED_CODEX_SOURCE_CRITICAL_FINDING_COUNTS = new Map<string, number>(
56+
REVIEWED_CODEX_SOURCE_LAYOUTS.flatMap((layout) => [...layout]),
57+
);
58+
4559
// Generated chunks can contain multiple reviewed execution sites. Counts are
4660
// part of the contract so an added or missing site fails the release scan.
4761
const OPTIONAL_REVIEWED_PUBLISHABLE_DIST_CRITICAL_FINDING_COUNTS = new Map<string, number>([
@@ -113,6 +127,53 @@ function normalizePackedFindingPath(packedPath: string): string {
113127
return packedPath;
114128
}
115129

130+
function expandReviewedFindingCounts(counts: ReadonlyMap<string, number>): string[] {
131+
return [...counts].flatMap(([key, count]) => Array.from({ length: count }, () => key));
132+
}
133+
134+
function resolveReviewedCodexSourceLayout(
135+
reviewedCriticalFindings: readonly string[],
136+
): string[] | undefined {
137+
const observedSourceFindings = reviewedCriticalFindings
138+
.filter((key) => REVIEWED_CODEX_SOURCE_CRITICAL_FINDING_COUNTS.has(key))
139+
.toSorted();
140+
return REVIEWED_CODEX_SOURCE_LAYOUTS.map(expandReviewedFindingCounts).find((layout) => {
141+
const expectedSourceFindings = layout.toSorted();
142+
return (
143+
expectedSourceFindings.length === observedSourceFindings.length &&
144+
expectedSourceFindings.every((key, index) => key === observedSourceFindings[index])
145+
);
146+
});
147+
}
148+
149+
function requiredReviewedFindingsForPackage(
150+
packageName: string,
151+
reviewedCriticalFindings: readonly string[],
152+
): string[] {
153+
const commonFindings = [...REQUIRED_REVIEWED_PUBLISHABLE_CRITICAL_FINDING_COUNTS].flatMap(
154+
([key, count]) =>
155+
key.startsWith(`${packageName}:`) ? Array.from({ length: count }, () => key) : [],
156+
);
157+
if (packageName !== "@openclaw/codex") {
158+
return commonFindings;
159+
}
160+
const sourceLayout = resolveReviewedCodexSourceLayout(reviewedCriticalFindings);
161+
if (!sourceLayout) {
162+
throw new Error(
163+
"@openclaw/codex: reviewed source findings must match exactly one complete known layout.",
164+
);
165+
}
166+
return [...commonFindings, ...sourceLayout];
167+
}
168+
169+
function isReviewedPublishableCriticalFinding(key: string): boolean {
170+
return (
171+
REQUIRED_REVIEWED_PUBLISHABLE_CRITICAL_FINDING_COUNTS.has(key) ||
172+
REVIEWED_CODEX_SOURCE_CRITICAL_FINDING_COUNTS.has(key) ||
173+
OPTIONAL_REVIEWED_PUBLISHABLE_DIST_CRITICAL_FINDING_COUNTS.has(key)
174+
);
175+
}
176+
116177
function expectedOptionalReviewedFindingsForPackedPath(
117178
packageName: string,
118179
packedPath: string,
@@ -261,10 +322,7 @@ async function scanPublishablePluginPackage(plugin: PublishablePluginPackage): P
261322
}
262323
const packedPath = normalizePackedFindingPath(toRepoPath(relative(stageDir, finding.file)));
263324
const key = `${plugin.packageName}:${finding.ruleId}:${packedPath}`;
264-
if (
265-
REQUIRED_REVIEWED_PUBLISHABLE_CRITICAL_FINDING_COUNTS.has(key) ||
266-
OPTIONAL_REVIEWED_PUBLISHABLE_DIST_CRITICAL_FINDING_COUNTS.has(key)
267-
) {
325+
if (isReviewedPublishableCriticalFinding(key)) {
268326
reviewedCriticalFindings.push(key);
269327
continue;
270328
}
@@ -358,21 +416,76 @@ describe("publishable plugin npm package install security scan", () => {
358416
).toEqual([]);
359417
});
360418

419+
it("accepts either complete reviewed Codex source layout", () => {
420+
const legacyLayout = expandReviewedFindingCounts(
421+
REVIEWED_CODEX_LEGACY_SOURCE_CRITICAL_FINDING_COUNTS,
422+
);
423+
const currentLayout = expandReviewedFindingCounts(
424+
REVIEWED_CODEX_CURRENT_SOURCE_CRITICAL_FINDING_COUNTS,
425+
);
426+
427+
expect(resolveReviewedCodexSourceLayout(legacyLayout)).toEqual(legacyLayout);
428+
expect(resolveReviewedCodexSourceLayout(currentLayout)).toEqual(currentLayout);
429+
});
430+
431+
const invalidCodexSourceLayouts: Array<[name: string, findings: string[]]> = [
432+
["absent", []],
433+
[
434+
"partial legacy",
435+
["@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/http.ts"],
436+
],
437+
[
438+
"partial current",
439+
["@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/sandbox-child.ts"],
440+
],
441+
[
442+
"mixed",
443+
[
444+
"@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/http.ts",
445+
"@openclaw/codex:dangerous-exec:src/app-server/transport-process-containment.ts",
446+
],
447+
],
448+
[
449+
"both complete",
450+
[
451+
...expandReviewedFindingCounts(REVIEWED_CODEX_LEGACY_SOURCE_CRITICAL_FINDING_COUNTS),
452+
...expandReviewedFindingCounts(REVIEWED_CODEX_CURRENT_SOURCE_CRITICAL_FINDING_COUNTS),
453+
],
454+
],
455+
[
456+
"duplicate occurrence",
457+
[
458+
...expandReviewedFindingCounts(REVIEWED_CODEX_CURRENT_SOURCE_CRITICAL_FINDING_COUNTS),
459+
"@openclaw/codex:dangerous-exec:src/app-server/transport-process-containment.ts",
460+
],
461+
],
462+
];
463+
464+
test.each(invalidCodexSourceLayouts)("rejects a %s Codex source layout", (_name, findings) => {
465+
expect(resolveReviewedCodexSourceLayout(findings)).toBeUndefined();
466+
});
467+
468+
it("does not review an unknown relocated Codex source finding", () => {
469+
const relocatedFinding =
470+
"@openclaw/codex:dangerous-exec:src/app-server/sandbox-exec-server/relocated.ts";
471+
472+
expect(isReviewedPublishableCriticalFinding(relocatedFinding)).toBe(false);
473+
expect(resolveReviewedCodexSourceLayout([relocatedFinding])).toBeUndefined();
474+
});
475+
361476
test.concurrent.each(publishablePluginPackages)(
362477
"keeps $packageName files clear of unexpected critical hits",
363478
async (plugin) => {
364479
const result = scanResultsByPackageName.get(plugin.packageName);
365480
if (!result) {
366481
throw new Error(`Missing package scan result for ${plugin.packageName}`);
367482
}
483+
expect(result.unexpectedCriticalFindings.toSorted()).toStrictEqual([]);
368484
const expectedReviewedCriticalFindings = [
369-
...[...REQUIRED_REVIEWED_PUBLISHABLE_CRITICAL_FINDING_COUNTS].flatMap(([key, count]) =>
370-
key.startsWith(`${plugin.packageName}:`) ? Array.from({ length: count }, () => key) : [],
371-
),
485+
...requiredReviewedFindingsForPackage(plugin.packageName, result.reviewedCriticalFindings),
372486
...result.expectedReviewedCriticalFindings,
373487
];
374488

375-
expect(result.unexpectedCriticalFindings.toSorted()).toStrictEqual([]);
376489
expect(result.reviewedCriticalFindings.toSorted()).toEqual(
377490
expectedReviewedCriticalFindings.toSorted(),
378491
);

0 commit comments

Comments
 (0)