Repository navigation
[CTX-1896] fix(terminal,ipc): require debug.inspect exactly on the plugin inspect methods (bitty#2921) - #3248
Conversation
…ugin inspect methods (bitty#2921) `require_inspect_scope` admitted the caller when it held *any* of `debug.inspect`, `debug.trace`, or `debug.control`, so a session granted only `debug.trace` (or only `debug.control`) passed the `debug.inspect` gate on `bitty.debug/listPlugins` and `bitty.debug/getPlugin`. The DevTools RFC's scope table takes the opposite position: the three debug scopes are independent grants, and "no scope is implied by connection or by holding another scope". `debug.trace` "does not imply `inspect`". The any-of check therefore handed a scope the caller does not own, which is what the 2026-11-19 P0-AC-025 campaign observed: `listPlugins` flipped from `ScopeDenied` to `PluginRuntimeUnavailable` for a trace-only holder, because the request reached the runtime. That is both an unauthorized read of plugin metadata (ids, versions, generations, manifest hashes, capabilities) and a runtime-attachment oracle for a client that may not inspect. The gate now names the one scope each registered method is accepted under and checks it exactly (`ServeContext::has_scope`, which is `ScopeSet::contains`, with no hierarchy subsumption). Per method in this file: - `bitty.debug/listPlugins` -> `Scope::DebugInspect` - `bitty.debug/getPlugin` -> `Scope::DebugInspect` No trace or control handler lives in this module (the trace/control methods stay on `bitty-ipc`'s fail-closed table), so those two are the whole set: a grep for the any-of shape in `crates/bitty-terminal/src` now finds nothing. The refusal keeps the accepted `scope` / `ScopeDenied` category and code and the same wording; the message still names the scope the method requires, now derived from the called scope instead of a hardcoded literal, so an inspect refusal reads byte-identically to before. Tests (`plugin_ipc::tests`, all new, suffixed `_2921`): - trace-only holder: `listPlugins` and `getPlugin` denied with `scope`/`ScopeDenied`, message names `debug.inspect` and not `debug.trace`; with the store detached the refusal is still `ScopeDenied`, never `PluginRuntimeUnavailable` (the pre-fix flip). - control-only holder: denied on both, same shape. - inspect-only holder: both methods served. - inspect + trace, inspect + control, all three: both methods served, so the required scope is neither widened nor narrowed by an extra grant. - trace-only holder through the registered dispatcher with a real attested peer proof: refused before the handler's runtime read, and the test first asserts the method is registered so the refusal cannot be `UnknownMethod`. Discrimination: in a copy of this worktree under the agent scratch directory with its own `CARGO_TARGET_DIR`, restoring the pre-fix `has_any_scope(&[DebugInspect, DebugTrace, DebugControl])` line makes the three denial tests fail (`test result: FAILED. 2 passed; 3 failed`) with `listPlugins` returning the row instead of the typed refusal; the two "allowed" tests still pass, so the rows discriminate on the gate change and not on fixture state. The lane worktree was not mutated for this. Gates (offline, in the lane worktree, `CARGO_TARGET_DIR` outside the tree): - `cargo fmt --all --check` - clean - `cargo clippy -p bitty-terminal --all-targets --offline -- -D warnings` - clean - `cargo test -p bitty-terminal --offline --bin bitty plugin_ipc` - 12 passed, 0 failed - `cargo test -p bitty-terminal --offline --bin bitty plugin_inspect` - 4 passed, 0 failed (includes the pre-existing both-tables dispatch test) - `cargo +1.85 check -p bitty-terminal --offline` - clean (MSRV 1.85: no let-chains, no `if let` guards) - `cargo +1.85 check -p bitty-terminal --offline --all-targets` - clean - `RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-terminal --no-deps --offline` - clean `bitty-ipc`'s own `require_debug_terminal_read` still accepts any debug scope for the terminal-reading methods; it is a pinned external dependency (`rev 9493674`), so this PR neither changes nor re-pins it. Related #2921
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Xuepoo
left a comment
There was a problem hiding this comment.
Review — bitty#3248 [CTX-1896] require debug.inspect exactly on the plugin inspect methods
Independent reviewer agent, guard tick 2026-11-19. Reviewed at head f978f5107a1c06a87c5074aaec00b1b3d4e63501 (1 file, +220/-7). Lane worktree read-only; all mutations run on a scratch copy with its own CARGO_TARGET_DIR.
1. Gate change is real — PASS
require_inspect_scopeis gone; the gate is nowfn require_scope(context: &ServeContext, scope: Scope, method: &str)atcrates/bitty-terminal/src/plugin_ipc.rs:184-196, checkingcontext.has_scope(scope)(:185).bitty.debug/listPluginspassesScope::DebugInspectatplugin_ipc.rs:496-500;bitty.debug/getPluginatplugin_ipc.rs:531-535.git grep -n 'has_any_scope' -- crates/bitty-terminal/src→ no matches.git grep -n 'require_inspect_scope'→ only a historical mention inside a test doc-comment (plugin_ipc.rs:929), no live call.has_scopeis exact-membership, no hierarchy:serve.rs:763-767(bitty-ipc9493674) →current_authorization().is_ok_and(|s| s.scopes.contains(scope)), andScopeSet::containsisBTreeSet::contains(bitty-ipc-api/src/scope.rs:227). An authorization read that errors yieldsfalse, i.e. still fail-closed.
2. Refusal shape preserved — PASS
plugin_ipc.rs:188-195: category"scope"(:189), code"ScopeDenied"(:190), messagepermission denied: scope '{}' denied for {method} (needs elevation)filled fromscope.as_str()(:191-194) → literally namesdebug.inspectfor both methods.- No success path for a non-inspect holder:
require_scope(...)?is the first statement of each handler and returnsErrbefore anyOk; the only registration table isplugin_ipc.rs:160-164, and the dispatcher test (:1053-1080) proves the refusal also holds on the wire path. - The typed
PluginRuntimeUnavailableverdict (plugin_ipc.rs:198-206) is now unreachable for a trace-only/control-only holder, since the scope check precedes thepublished.attachedread.
3. Fail-closed ordering — PASS
listPlugins: gateplugin_ipc.rs:496→ params read:501(list_generation) → store read:503-509(lock_store(),!published.attached).getPlugin: gateplugin_ipc.rs:531→ params read:536→validate_plugin_id:544→ store read:546-556.- Both gate before any store read or runtime/attachment probe, so an unauthorized caller cannot even distinguish attached vs detached by timing or by error shape.
4. Tests discriminate — PASS (mutation-proved)
Baseline on the scratch copy (unmodified PR tree), cargo test -p bitty-terminal --offline --bin bitty plugin_ipc: 12 passed, 0 failed, 1662 filtered out.
Mutation A — gate reverted to the pre-fix any-of form (has_any_scope(&[DebugInspect, DebugTrace, DebugControl])), signature and message kept: 9 passed, 3 failed:
trace_only_holder_is_denied_on_the_plugin_inspect_methods_2921 FAILED plugin_ipc.rs:944
control_only_holder_is_denied_on_the_plugin_inspect_methods_2921 FAILED plugin_ipc.rs:987
trace_only_holder_is_refused_through_the_dispatcher_2921 FAILED plugin_ipc.rs:1077
test result: FAILED. 9 passed; 3 failed; 0 ignored
Each failure printed the leaked payload, e.g. debug.trace must not list plugins: "{\"plugins\":[{\"id\":\"xuepoo.one\",…}]}" — exactly the defect from bitty#2921, reproduced.
Mutation B — exact gate kept, message made to name 'debug.trace' instead of debug.inspect: 10 passed, 2 failed:
…trace_only… FAILED plugin_ipc.rs:947
…control_only… FAILED plugin_ipc.rs:990
the refusal must name the scope the method requires: permission denied: scope 'debug.trace' denied for bitty.debug/listPlugins (needs elevation)
So the message assertions (contains("'debug.inspect'") plus the negative !contains("'debug.trace'") / !contains("'debug.control'")) bite independently of the gate assertion. Tests that must keep passing do: inspect_only_holder_is_allowed… and inspect_plus_trace_or_control_holder_is_allowed_2921 stayed green under both mutations. Scratch copy left as-is.
5. No coverage removed, no gate weakened — PASS
- Removed lines in the diff: 7 total, all either the old gate body (
require_inspect_scope+has_any_scopeline + fixed message) or the two call sites / one doc sentence. Zero removed assertions. - No
#[allow(...)], no#[ignore], nocfg(test)-only loosening, no scope-set widening anywhere in the diff. The only behavioral change is narrowing an any-of admission to an exact one; the trace/control methods are untouched (they live on bitty-ipc's table).
6. Comments cite the accepted rule accurately — PASS (RFC text read)
Spot-checked bitty-terminal-docs/specifications/devtools-rfc.md:
:389-391— "Separate consent grants each scope, and no scope is implied by connection or by holding another scope" (the doc-comment atplugin_ipc.rs:170-173quotes this verbatim).:424-425— the method table assignsinspectto bothbitty.debug/listPluginsandbitty.debug/getPlugin.:397—debug.trace"Does not implyinspect";:398—debug.control"Does not implyinspectortrace".:1145-1147— acceptance requires "connection alone grants none ofdebug.inspect,debug.trace, ordebug.control" with a negative test per matrix cell (P0-AC-025 parity), which the new tests supply.
7. MSRV safety — PASS
- No let-chains and no
if letmatch guards in the added lines (git show | grep '^+'forif let/let … &&/while let→ none).require_scopebody is a plainif context.has_scope(scope) { … }. - MSRV is 1.85 (
Cargo.toml:37); CI "MSRV 1.85 check" is pass on this head, as is the rest of the PR's check suite (Quality gates 1/2, Linux Wayland/X11, macOS, Windows, deny/audit).
Residuals (non-blocking, follow-ups)
- bitty-ipc pinned rev still carries the same any-of gate.
crates/bitty-ipc/src/devtools/plugin_runtime.rs:66(rev9493674) keepsrequire_inspect_scopeashas_any_scope(&[DebugInspect, DebugTrace, DebugControl]), andrequire_trace_scopeat:78admitsDebugControlfor the trace stream. Out of scope for this repo'scrates/bitty-terminal/src, and unreachable here because bitty-terminal registers both method names itself, but any other binary serving bitty-ipc's default plugin-runtime table keeps the bitty#2921 defect. File against bitty-ipc. getPlugin's refusal message is never asserted (onlycategory/codeatplugin_ipc.rs:958-959,:1001-1002); mutation B proved the message assertions only bite through thelistPluginspath. Cheap to close.- The detached-store (
publish(None)) oracle assertion lives only in the trace test (:964-972); the control test does not repeat it. - No test exercises
has_scope's fail-closed branch (authorization read error →false) on these two methods.
VERDICT: APPROVE
Defect
crates/bitty-terminal/src/plugin_ipc.rs:166require_inspect_scopeadmitteda caller that held any of
debug.inspect,debug.trace,debug.control,so a session granted only
debug.trace(or onlydebug.control) passed thedebug.inspectgate onbitty.debug/listPluginsandbitty.debug/getPlugin.The DevTools RFC scope table takes the opposite position: the three debug
scopes are independent grants, and "no scope is implied by connection or by
holding another scope";
debug.trace"does not implyinspect"(
bitty-terminal-docsspecifications/devtools-rfc.md, "Scopes"). The any-ofcheck handed out a scope the caller does not own.
Observed during the 2026-11-19 P0-AC-025 campaign (bitty#2921):
listPluginsflipped from
ScopeDeniedtoPluginRuntimeUnavailablefor a trace-onlyholder, i.e. the request reached the runtime. That is both an unauthorized read
of plugin metadata (ids, versions, generations, manifest hashes, capabilities)
and a runtime-attachment oracle for a client that may not inspect.
Gate change, per method
One function,
require_scope(context, scope, method), now declares and checksthe single scope the accepted table assigns each method
(
ServeContext::has_scope->ScopeSet::contains, exact membership, nohierarchy subsumption):
bitty.debug/listPluginsdebug.inspect/debug.trace/debug.controldebug.inspectbitty.debug/getPlugindebug.inspect/debug.trace/debug.controldebug.inspectNo trace or control handler lives in this module — those methods stay on
bitty-ipc's fail-closed table — so these two are the whole set: a grep forthe any-of shape in
crates/bitty-terminal/srcnow returns nothing.The refusal keeps the accepted fail-closed shape (
categoryscope, codeScopeDenied) and the same wording; the message still names the scope themethod requires, now derived from the called scope rather than a hardcoded
literal, so an inspect refusal is byte-identical to before. Only the set of
callers that receive it changed.
Test matrix
New tests in
plugin_ipc::tests, suffixed_2921:listPluginsgetPlugininspect_scope_is_required_and_params_fail_closed)debug.traceonlyscope/ScopeDenied, namesdebug.inspect)debug.controlonlyscope/ScopeDenied, namesdebug.inspect)debug.inspectonlydebug.inspect+debug.tracedebug.inspect+debug.controlAdditional assertions:
requires
ScopeDenied, so the refusal can never degrade intoPluginRuntimeUnavailable— the exact pre-fix symptom.trace_only_holder_is_refused_through_the_dispatcher_2921drivesDispatcher::dispatchon the registered table with a real attested peerproof and asserts the method is registered first, so the refusal is the gate
and not
UnknownMethod.debug.inspectand must not name the scopethe caller already holds.
Discrimination proof
In a copy of the worktree under the agent scratch directory with its own
CARGO_TARGET_DIR, restoring the pre-fix linecontext.has_any_scope(&[Scope::DebugInspect, Scope::DebugTrace, Scope::DebugControl])and running the new tests gives:
The three failures are the trace-only, control-only, and dispatcher denial rows,
each panicking where the typed refusal was expected and
listPluginsreturnedthe published row instead. The two "allowed" rows still pass, so the suite
discriminates on the gate change and not on fixture state. The lane worktree
was not mutated for this revert.
Gates run (offline, lane worktree,
CARGO_TARGET_DIRoutside the tree)cargo fmt --all --checkcargo clippy -p bitty-terminal --all-targets --offline -- -D warningscargo test -p bitty-terminal --offline --bin bitty plugin_ipccargo test -p bitty-terminal --offline --bin bitty plugin_inspectcargo +1.85 check -p bitty-terminal --offlinecargo +1.85 check -p bitty-terminal --offline --all-targetsRUSTDOCFLAGS="-D warnings" cargo doc -p bitty-terminal --no-deps --offlineThe
plugin_inspectfilter additionally re-runs the pre-existingipc_serve::tests::plugin_inspect_dispatches_the_activated_rows_on_both_tables,so both registration tables still serve the snapshot to a
debug.inspectholder.
Scope of this PR
It moves the scope-distinctness half of P0-AC-025 for these two methods only.
bitty-ipc's ownrequire_debug_terminal_readstill accepts any debug scopefor the terminal-reading methods; it is a pinned external dependency
(
rev 9493674), so this PR neither changes nor re-pins it. Nothing here closesbitty#2921 or flips a P0 control to "verified".
Related #2921
Summary by CodeRabbit
debug.inspectpermission, whether or not a runtime is attached. Calls without this permission are denied.