Skip to content

Commit 7ceba6a

Browse files
committed
fix(runtime): keep the host-error marker off a host error's enumerable keys; offer refusals in the hook form
Claude-Session: https://claude.ai/code/session_01WGufzfyVQuRsL6SRGuKCem Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3812688 commit 7ceba6a

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎packages/runtime/src/sandbox/quickjs-runner.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,9 +1500,10 @@ function hostErrorToVm(vm: QuickJSContext, err: unknown): QuickJSHandle {
15001500
}
15011501
// [#26170] Every marshalled host error carries the `message` and `code` it
15021502
// crossed with, so the reject handler can tell it leaving unchanged from
1503-
// an error the body made (see SANDBOX_HOST_ERROR_OF_PROP).
1503+
// an error the body made (see SANDBOX_HOST_ERROR_OF_PROP). Not enumerable:
1504+
// the body reads the same keys off a host error as before (#3918's allowlist).
15041505
const hostOf = vm.newString(JSON.stringify([vmMessage, typeof e?.code === 'string' && e.code ? e.code : null]));
1505-
vm.setProp(errH, SANDBOX_HOST_ERROR_OF_PROP, hostOf);
1506+
vm.defineProp(errH, SANDBOX_HOST_ERROR_OF_PROP, { value: hostOf, configurable: true, enumerable: false });
15061507
hostOf.dispose();
15071508
} catch {
15081509
/* keep the bare name/message error */

‎packages/spec/src/data/hook.form.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ export const hookForm = defineForm({
4646
{ field: 'memoryMb', type: 'number', helpText: 'Per-invocation memory cap (MB, max 256)' },
4747
],
4848
},
49+
{
50+
field: 'refusals',
51+
type: 'record',
52+
helpText: 'Refusals the body may throw, by code — the body throws an error carrying the code, and the caller reads this message',
53+
keyField: {
54+
field: 'code',
55+
label: 'Code',
56+
placeholder: 'CREDIT_LIMIT',
57+
helpText: 'SCREAMING_SNAKE code the body throws',
58+
regex: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$',
59+
},
60+
fields: [
61+
{ field: 'message', type: 'text', required: true, helpText: 'What the user reads (translated per locale)' },
62+
{ field: 'status', type: 'number', helpText: 'HTTP status, 400–499 (default 400)' },
63+
],
64+
},
4965
],
5066
},
5167
{

0 commit comments

Comments
 (0)