Skip to content

[CTX-1896] fix(terminal,ipc): require debug.inspect exactly on the plugin inspect methods (bitty#2921) - #3248

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1896/devtools-scope
Nov 19, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1896/devtools-scope

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Defect

crates/bitty-terminal/src/plugin_ipc.rs:166 require_inspect_scope admitted
a caller that held any of debug.inspect, debug.trace, 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 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"
(bitty-terminal-docs specifications/devtools-rfc.md, "Scopes"). The any-of
check handed out a scope the caller does not own.

Observed during the 2026-11-19 P0-AC-025 campaign (bitty#2921): listPlugins
flipped from ScopeDenied to PluginRuntimeUnavailable for a trace-only
holder, 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 checks
the single scope the accepted table assigns each method
(ServeContext::has_scope -> ScopeSet::contains, exact membership, no
hierarchy subsumption):

Method Required scope (before) Required scope (after)
bitty.debug/listPlugins any of debug.inspect / debug.trace / debug.control debug.inspect
bitty.debug/getPlugin any of debug.inspect / debug.trace / debug.control debug.inspect

No 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 for
the any-of shape in crates/bitty-terminal/src now returns nothing.

The refusal keeps the accepted fail-closed shape (category scope, code
ScopeDenied) and the same wording; the message still names the scope the
method 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:

Holder's debug scopes listPlugins getPlugin
none (pre-existing inspect_scope_is_required_and_params_fail_closed) denied denied
debug.trace only denied (scope/ScopeDenied, names debug.inspect) denied
debug.control only denied (scope/ScopeDenied, names debug.inspect) denied
debug.inspect only served served
debug.inspect + debug.trace served served
debug.inspect + debug.control served served
all three served served

Additional assertions:

  • The trace-only row repeats the check with the publication detached and still
    requires ScopeDenied, so the refusal can never degrade into
    PluginRuntimeUnavailable — the exact pre-fix symptom.
  • trace_only_holder_is_refused_through_the_dispatcher_2921 drives
    Dispatcher::dispatch on the registered table with a real attested peer
    proof and asserts the method is registered first, so the refusal is the gate
    and not UnknownMethod.
  • The refusal message must name debug.inspect and must not name the scope
    the 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 line
context.has_any_scope(&[Scope::DebugInspect, Scope::DebugTrace, Scope::DebugControl])
and running the new tests gives:

test result: FAILED. 2 passed; 3 failed

The three failures are the trace-only, control-only, and dispatcher denial rows,
each panicking where the typed refusal was expected and listPlugins returned
the 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_DIR outside the tree)

Gate Result
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
cargo +1.85 check -p bitty-terminal --offline clean (MSRV 1.85)
cargo +1.85 check -p bitty-terminal --offline --all-targets clean
RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-terminal --no-deps --offline clean

The plugin_inspect filter additionally re-runs the pre-existing
ipc_serve::tests::plugin_inspect_dispatches_the_activated_rows_on_both_tables,
so both registration tables still serve the snapshot to a debug.inspect
holder.

Scope of this PR

It moves the scope-distinctness half of P0-AC-025 for these two methods only.
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. Nothing here closes
bitty#2921 or flips a P0 control to "verified".

Related #2921

Summary by CodeRabbit

  • Bug Fixes
    • Plugin listing and retrieval now require the debug.inspect permission, whether or not a runtime is attached. Calls without this permission are denied.

…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
@Xuepoo Xuepoo added this to the v0.1.0 milestone Nov 19, 2026
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:platform Area: platform / windowing area:security Area: security corpus / audit labels Nov 19, 2026
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The listPlugins and getPlugin methods now require debug.inspect. Callers with only debug.trace or debug.control receive a scope error. Tests cover both methods, detached-store behavior, combinations of scopes, and dispatcher denial.

Changes: Plugin inspection access

Layer / File(s) Summary
Require the inspection scope
crates/bitty-terminal/src/plugin_ipc.rs
The scope check for listPlugins and getPlugin now requires debug.inspect. The module documentation describes this requirement.
Test scope behavior
crates/bitty-terminal/src/plugin_ipc.rs
Tests cover denied and permitted scope combinations, detached-store behavior, and denial through the dispatcher.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • bitty-terminal/bitty#2778: Adds the test-mode read-only store of plugin lifecycle rows used by the same listPlugins and getPlugin methods.
Merge Risk: Minimal · up to f978f

This change tightens plugin listing and inspection so that only callers with the debug.inspect grant are allowed, and trace-only or control-only callers are refused with the existing scope error. The change is small, well tested and easy to revert. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the plugin inspect methods now require the exact debug.inspect scope. It also names the affected area (terminal, ipc). The title is 102 characters, which is longer tha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the plugin inspect methods now require the exact debug.inspect scope. It also names the affected area (terminal, ipc). The title is 102 characters, which is longer than ideal but still readable. The ticket tag and PR number do not affect the assessment.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 30639501-3536-430d-85a3-a91bfa580fce
Commits

Reviewing files that changed from the base of the PR and between 04253d4 and f978f51.

Files selected for processing: 1

  • crates/bitty-terminal/src/plugin_ipc.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_scope is gone; the gate is now fn require_scope(context: &ServeContext, scope: Scope, method: &str) at crates/bitty-terminal/src/plugin_ipc.rs:184-196, checking context.has_scope(scope) (:185).
  • bitty.debug/listPlugins passes Scope::DebugInspect at plugin_ipc.rs:496-500; bitty.debug/getPlugin at plugin_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_scope is exact-membership, no hierarchy: serve.rs:763-767 (bitty-ipc 9493674) → current_authorization().is_ok_and(|s| s.scopes.contains(scope)), and ScopeSet::contains is BTreeSet::contains (bitty-ipc-api/src/scope.rs:227). An authorization read that errors yields false, i.e. still fail-closed.

2. Refusal shape preserved — PASS

  • plugin_ipc.rs:188-195: category "scope" (:189), code "ScopeDenied" (:190), message permission denied: scope '{}' denied for {method} (needs elevation) filled from scope.as_str() (:191-194) → literally names debug.inspect for both methods.
  • No success path for a non-inspect holder: require_scope(...)? is the first statement of each handler and returns Err before any Ok; the only registration table is plugin_ipc.rs:160-164, and the dispatcher test (:1053-1080) proves the refusal also holds on the wire path.
  • The typed PluginRuntimeUnavailable verdict (plugin_ipc.rs:198-206) is now unreachable for a trace-only/control-only holder, since the scope check precedes the published.attached read.

3. Fail-closed ordering — PASS

  • listPlugins: gate plugin_ipc.rs:496 → params read :501 (list_generation) → store read :503-509 (lock_store(), !published.attached).
  • getPlugin: gate plugin_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_scope line + fixed message) or the two call sites / one doc sentence. Zero removed assertions.
  • No #[allow(...)], no #[ignore], no cfg(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 at plugin_ipc.rs:170-173 quotes this verbatim).
  • :424-425 — the method table assigns inspect to both bitty.debug/listPlugins and bitty.debug/getPlugin.
  • :397 — debug.trace "Does not imply inspect"; :398 — debug.control "Does not imply inspect or trace".
  • :1145-1147 — acceptance requires "connection alone grants none of debug.inspect, debug.trace, or debug.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 let match guards in the added lines (git show | grep '^+' for if let / let … && / while let → none). require_scope body is a plain if 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)

  1. bitty-ipc pinned rev still carries the same any-of gate. crates/bitty-ipc/src/devtools/plugin_runtime.rs:66 (rev 9493674) keeps require_inspect_scope as has_any_scope(&[DebugInspect, DebugTrace, DebugControl]), and require_trace_scope at :78 admits DebugControl for the trace stream. Out of scope for this repo's crates/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.
  2. getPlugin's refusal message is never asserted (only category/code at plugin_ipc.rs:958-959, :1001-1002); mutation B proved the message assertions only bite through the listPlugins path. Cheap to close.
  3. The detached-store (publish(None)) oracle assertion lives only in the trace test (:964-972); the control test does not repeat it.
  4. No test exercises has_scope's fail-closed branch (authorization read error → false) on these two methods.

VERDICT: APPROVE

@Xuepoo
Xuepoo merged commit 27f472d into main Nov 19, 2026
21 checks passed
@Xuepoo
Xuepoo deleted the ctx-1896/devtools-scope branch November 19, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area: platform / windowing area:security Area: security corpus / audit fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant