Skip to content

Commit 3b957f9

Browse files
test(rest): sandbox crash leak checks match a long unique marker, not the short word boom (#25928)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DGwpW37CMTDznXmHEda2Sn2)_ Fixes #25714 Clause-②: no Metadata-protocol: none ## What changed Test-only. The sandbox-crash leak checks matched the short word `boom` (plus `TypeError`) against the whole serialized response, and the import job id (base36 timestamp plus random tail) can spell `boom` by chance. The injected crash now carries a long unique marker, and the leak pattern matches that marker plus `TypeError` (a lowercase base36 id cannot spell `TypeError`). The check is no looser: any leak of the fault's words still fails it; no retry, no skip. - `packages/rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts`: new `CRASH_WORDS` / `CRASH_LEAK`; `sandboxCrash`, the `sandboxOwnFault` inner-hook row, and the three former `TypeError-or-boom` patterns (the CRASHED rows of the two tables and the inner-hook row) use them. - `packages/rest/src/rest-sandbox-declared-status.test.ts`: same family (the `mapDataError` crash row); same marker. Producer check: the real producer is the test sentinel itself (id from `rest-server.ts` import job creation); no product code changes. ## Verification - `git grep -n` for the old whole-body short-sentinel pattern in `packages/rest/src`: no hits (exit 1). - Both files via vitest at head 0728391: `Test Files 2 passed (2)`, `Tests 589 passed (589)`. - Ablation (committed fix first; mutation of `sandboxFaultAnswer` in `error-response.ts` so the fault's `.message` reaches the body; anchor hit 1 to 0, blob 77862fd to 25c0c58f; the mutated line read back from disk; source-resolved, no dist involved): `Tests 46 failed | 543 passed (589)`, e.g. `Expected: "Internal server error" Received: "hook 'mz_guard' threw: TypeError: __OS_SANDBOX_FAULT_7f3a9c__"`. Restored with `git checkout HEAD`; `git status --porcelain` empty and the file blob hash equals the HEAD blob (77862fd). - `dispatch-gates --ran`: 56 derived, 55 run exit 0, 1 NOT-MEASURED (`pnpm check:dual-build-cjs-loads` exit 3, PREREQUISITE NOT MET: only the rest closure is built locally). `check-plugin-teardown-shape --self-test` first exited 3 on a shallow clone, then 0 after `git fetch --unshallow`. - `pnpm lint`: exit 0. ## Acceptance notes - Both acceptance lines hold (see Verification). Test-only, so `skip-changeset`, no changeset. - No out-of-scope findings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01TFnDdepdwyDJeM2kJ4GtMy Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9407318 commit 3b957f9

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎packages/rest/src/rest-sandbox-declared-status.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ describe('[#9967] a sandboxed body that declares a 5xx takes the sanitised 5xx a
161161
// reverse verification
162162
// ---------------------------------------------------------------------------
163163

164+
// A long unique marker, not a short word: the whole-body match must not be
165+
// spellable by chance by a generated id or timestamp.
166+
const CRASH_WORDS = '__OS_SANDBOX_FAULT_7f3a9c__';
167+
164168
describe('[#9967] the pinned defaults are untouched', () => {
165169
it('an UNDECLARED body throw keeps the verbatim-message 400 with no code', () => {
166170
const r = mapDataError(sandboxRefusal(), 'showcase_task');
@@ -175,12 +179,12 @@ describe('[#9967] the pinned defaults are untouched', () => {
175179
// happens to have a `status` property is still a script fault, never
176180
// an author-declared refusal.
177181
const err = sandboxRefusal({ status: 403 });
178-
err.innerMessage = 'TypeError: boom';
182+
err.innerMessage = `TypeError: ${CRASH_WORDS}`;
179183
const r = mapDataError(err, 'showcase_task');
180184

181185
expect(r.status).toBe(500);
182186
expect(r.body.code).toBe('INTERNAL_ERROR');
183-
expect(JSON.stringify(r.body)).not.toMatch(/TypeError|boom/);
187+
expect(JSON.stringify(r.body)).not.toMatch(new RegExp(`TypeError|${CRASH_WORDS}`));
184188
});
185189
});
186190

‎packages/rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,21 @@ function sandboxRefusal(): Error {
7474
return Object.assign(err, { innerMessage: SENTENCE });
7575
}
7676

77+
/**
78+
* The words a crashed body's native error carries. A long unique marker, never
79+
* a short word: the leak checks match the WHOLE response body, which also holds
80+
* generated ids and timestamps in base36, and a short sentinel such as `boom`
81+
* can be spelled by one of those by chance. `TypeError` stays in the pattern
82+
* because a lowercase base36 id cannot spell it.
83+
*/
84+
const CRASH_WORDS = '__OS_SANDBOX_FAULT_7f3a9c__';
85+
const CRASH_LEAK = new RegExp(`TypeError|${CRASH_WORDS}`);
86+
7787
/** A body that CRASHED: the runner sets `innerMessage` to the native error text. */
7888
function sandboxCrash(): Error {
79-
const err = new Error("hook 'mz_guard' threw: TypeError: boom");
89+
const err = new Error(`hook 'mz_guard' threw: TypeError: ${CRASH_WORDS}`);
8090
err.name = 'SandboxError';
81-
return Object.assign(err, { innerMessage: 'TypeError: boom' });
91+
return Object.assign(err, { innerMessage: `TypeError: ${CRASH_WORDS}` });
8292
}
8393

8494
const WRITE_ROWS = REST_ROUTE_LEDGER.filter((row) => /^(POST|PUT|PATCH|DELETE) /.test(row.route));
@@ -451,7 +461,7 @@ function sandboxDeclared5xx(): Error {
451461
*/
452462
describe('[#22718] §4 a sandboxed body the doors answer as a fault reads as that fault on both import doors', () => {
453463
it.each([
454-
['a body that CRASHED', sandboxCrash, /TypeError|boom/],
464+
['a body that CRASHED', sandboxCrash, CRASH_LEAK],
455465
['a refusal that declared a 5xx', sandboxDeclared5xx, /ledger/],
456466
] as const)('%s', async (_label, error, leak) => {
457467
const doors: unknown[] = [];
@@ -602,7 +612,7 @@ const OWN_FAULT = { status: 500, code: 'INTERNAL_ERROR' } as const;
602612
* CONTROL for {@link SANDBOX_OWN_FAULTS}: unchanged by that card.
603613
*/
604614
const SANDBOX_FAULT_CONTROLS = [
605-
['a body that CRASHED', sandboxCrash, { status: 500, code: 'INTERNAL_ERROR' }, /TypeError|boom/],
615+
['a body that CRASHED', sandboxCrash, { status: 500, code: 'INTERNAL_ERROR' }, CRASH_LEAK],
606616
['a refusal that declared a 5xx', sandboxDeclared5xx, { status: 503, code: 'SERVICE_UNAVAILABLE' }, /ledger/],
607617
] as const;
608618

@@ -627,7 +637,7 @@ const SANDBOX_OWN_FAULTS = [
627637
['the sandbox\'s own fault: a missing ctx.api method naming the object',
628638
sandboxOwnFault(`ctx.api.object('${OBJECT}').find not implemented`), OWN_FAULT, /implemented|ctx\.api/],
629639
['the sandbox\'s own fault: a nested body\'s crash relayed one VM hop up',
630-
sandboxOwnFault("hook 'mz_inner' threw: TypeError: boom"), OWN_FAULT, /TypeError|boom/],
640+
sandboxOwnFault(`hook 'mz_inner' threw: TypeError: ${CRASH_WORDS}`), OWN_FAULT, CRASH_LEAK],
631641
] as const;
632642

633643
const SANDBOX_FAULTS = [...SANDBOX_FAULT_CONTROLS, ...SANDBOX_OWN_FAULTS] as const;

0 commit comments

Comments
 (0)