Skip to content

[finding] ctx.log.debug is inferred, granted and documented, but the sandbox never installs it — a body calling it throws TypeError: not a function #7661

Description

@os-help

Found while fixing #7448 (PR #7660). Out of scope there — that card is the observability of ctx.log.{info,warn,error}; this is a fourth method that does not exist. Filed rather than folded in, per Prime Directive #10. Unassigned — recording only.

The gap

ctx.log.debug is declared on three surfaces and implemented on none.

SurfaceSaysAnchor (main @ 245d1dc)
CLI capability extractormatches debug, grants the log capabilitypackages/cli/src/utils/extract-hook-body.ts:56/ctx\.log\.(?:info|warn|error|debug)\b/
Docslists ctx.log.info / warn / error / debuglogcontent/docs/automation/hook-bodies.mdx:317
Sandbox ScriptContextdeclares info / warn / error onlypackages/runtime/src/sandbox/script-runner.ts:243
QuickJS VM installinstalls info / warn / error onlypackages/runtime/src/sandbox/quickjs-runner.ts:639for (const level of ['info', 'warn', 'error'] as const)

So an author writes ctx.log.debug(…), the CLI reads it, infers ['log'] and emits a body whose declared capability is satisfied — and the call then throws inside the VM.

Measured

Hook body ctx.log.debug('hi') with capabilities: ['log'], run through hookBodyRunnerFactory + QuickJSScriptRunner with a logger that has a real debug method:

hook 'h' threw: TypeError: not a function

Not a silent drop — the hook fails. Under onError: 'abort' that aborts the write.

Why this is the crypto.hash shape again

script-runner.ts:249-258 documents the precedent in its own comment: crypto.hash carried a signature, a capability token and CLI build-time inference for a function the sandbox never installed, so the one call it typed threw inside the VM. It was removed rather than implemented (#4391, ADR-0049 enforce-or-remove). ctx.log.debug is the same shape one member over — and unlike hashing it has no security-surface argument against implementing it.

Decision needed (enforce-or-remove)

Enforcing looks right here (a body emitting debug-level diagnostics is exactly what --log-level debug is for), but it is a capability-surface call, not a bug fix, so it should be decided rather than assumed.

Dedup

Searched open issues for ctx.log, log.debug, capability log, extract-hook-body: no existing card. #7448 is the adjacent one and covers only the three installed methods.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions