Skip to content

Commit 272753b

Browse files
committed
docs(runtime): note the hook capability refusal beside the fault contract, add changeset
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5o5GCE3vGxq6G24dZu
1 parent 818ff4b commit 272753b

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): a hook refused for a missing capability answers a coded 403 naming the hook and the capability, not a bare 500 (#26903)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
**What was wrong.** A hook whose sandboxed body calls something its `body.capabilities` does not grant (for example `ctx.api.object('note').find(...)` without `api.read`) is refused by the capability check. The QuickJS runner marked that denial as its own fault, so a save on the hook's object under `onError: 'abort'` answered `500 INTERNAL_ERROR` with `Internal server error`. Neither the caller nor the author was told which hook, or which capability, or what to change.
11+
12+
**What changes.** In a hook body, a capability denial is now a refusal. `POST /api/v1/data/OBJECT` (and every other door that answers through `mapDataError`) answers `403 INSUFFICIENT_PRIVILEGES`, an existing standard catalog code, with a sentence such as `capability 'api.read' not granted to hook 'note_guard' (called ctx.api.object('note').find). Grant it by adding 'api.read' to the hook's body.capabilities.` Nothing is written. The BodyRunner logs it once at `info` as a refusal, not at `error` with a stack. This applies to every gate: `api.read`, `api.write`, `api.transaction`, `crypto.uuid` and `log`, and `ctx.title(field)`.
13+
14+
**Unchanged.** The capability check is exactly as strict as before, and a hook that has the capability runs as before. Under `onError: 'log'` the denial is still recorded on the `[hook] handler failed (onError=log; suppressing)` line, now with the remedy, and the save proceeds. An action or job body's capability denial still answers `500 INTERNAL_ERROR`. No code is added.

‎packages/runtime/src/sandbox/capability-denial-is-a-fault.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
* `domains/actions-fault-vs-rejection.test.ts`, which already states that a
2727
* `SandboxError` with no `innerMessage` is a 500 — this file is what makes a
2828
* real capability denial actually arrive in that shape.
29+
*
30+
* [#26903] These are ACTION-origin denials. A HOOK body's denial is a coded
31+
* refusal (`403 INSUFFICIENT_PRIVILEGES`) since that card, pinned by
32+
* `hook-capability-denial-is-a-refusal.integration.test.ts`.
2933
*/
3034

3135
import { describe, it, expect } from 'vitest';

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ export class QuickJSScriptRunner implements ScriptRunner {
486486
// as a CRASH and answers 500 through `errorFromThrown`, instead of
487487
// the 400 a denial used to get — and the client sees the capability
488488
// text without the `SandboxError: ` debug prefix.
489+
// [#26903] A HOOK body's capability denial does not arrive here: it
490+
// crosses as a coded refusal (`throwCapabilityDenial`) and takes the
491+
// relay below like a body's own coded throw.
489492
if (info?.sandboxFault) {
490493
throw new SandboxError(withoutSandboxErrorPrefix(String(errStr)));
491494
}
@@ -2017,6 +2020,11 @@ export class SandboxError extends Error {
20172020
* the wrapped `.message` stays for server logs. Undefined for the sandbox's
20182021
* own internal errors (capability denials, timeouts, marshalling failures),
20192022
* which have no user-meaningful inner message.
2023+
*
2024+
* [#26903] Except a HOOK body's capability denial: that is a refusal naming
2025+
* the hook and the capability, so it carries this field and its `code`/
2026+
* `status` (see `throwCapabilityDenial`). An action or job body's denial is
2027+
* still the fault described above.
20202028
*/
20212029
readonly innerMessage?: string;
20222030
/**

0 commit comments

Comments
 (0)