Skip to content

M1 Identity + async proposals (v0.3.0 milestone 1): per-agent tokens and scopes, the agent named in the bar, and no client call ever waits on a human - #4

Open
ayushap18 wants to merge 1 commit into
mainfrom
m1-identity

Conversation

@ayushap18

Copy link
Copy Markdown
Owner

Milestone 1 of the v0.3.0 plan. Built one unit at a time, then attacked by four adversaries; all four found something, all fixed with a test.

211 backend tests (was 183) · 55 frontend (was 49) · zero warnings. agent.rs has zero changed lines vs main; enter_approves, agent_propose, agent_decide, decision_stands, MIN_REVIEW byte-identical; pty_write_internal still exactly 3 callers; the PTY write still lexically after the approval check.

Why

The hub had one bearer token and no identity, so the bar could only say "external agent"; and run_command blocked the client's HTTP call until the human pressed Enter — Codex and Cursor time out at ~60 s, so two of three target agents could not use it.

What

  • Per-agent tokens and scopes (/mcp agent add|list|show|revoke). Scopes read | journal | propose | message; journal deliberately not default. A read-only agent cannot even learn run_command exists. Legacy single token migrates to agent default; downgrade fails closed.
  • Identity from the bearer only. No tool takes from/as. A foreign proposal id answers exactly like an unknown one. Agent names are [a-z0-9][a-z0-9_-]{0,31}, reserved words refused, and an adversarial table (bidi, ·, whitespace, 33 chars, run?) is a test — the name is rendered in the approval bar and must not be able to forge that line.
  • The bar names who asks: codex · run? ⌘⏎ approve · esc deny. An external proposal with an empty agent is not approvable by any key.
  • Async proposals. run_command { command, wait_ms } returns within 25 s with a proposal_id; await_decision polls. There is no approval timeout — the human takes as long as they like. Proposal store bounded at 64.
  • Abuse limits: 30 s global deny cooldown, 1 pending proposal per agent, 4 total; refusals never show a bar.
  • Long commands readable in full before approval (read-only block above the bar, closes a documented danger-gate limitation).
  • hub_state read-only IPC (no token ever; tested for 64-hex substrings). Client handshake replays for Claude Code, Codex, Cursor.

Found by the adversaries and fixed

  • initialize told every caller that run_command exists regardless of scope — the propose/poll contract is now shown only to propose-scoped agents.
  • The "chord rule is byte-identical" test could not fail: its needle matched its own source line. Tests now grep only the production half of the file.
  • A denial's cooldown could be outrun by a caller that read the budget before the Esc landed — the cooldown is stamped before the guard drops and re-checked at the gate.
  • The four-surface drift test compared only the form column, so README could contradict /help about what a command does — descriptions are compared too.

Not verified

Whether a real Codex or Cursor session survives a 3-minute unanswered proposal — needs a real client. Nothing here has run in the app.

… named in the bar, and no client call ever waits on a human

The hub had ONE bearer token and no identity, so the approval bar could only
say "external agent"; and run_command blocked the client's HTTP call until the
human pressed Enter — Codex and Cursor time out at ~60 s, so two of the three
target agents could not use the hub at all.

REGISTRY. AgentToken { name, token, scopes, worktree } with no Debug derive (a
derived one would put the token into panic messages). Scopes read | journal |
propose | message; journal is deliberately not a default. TOOL_SCOPES is the
authorization table: a tool absent from it is unreachable by anyone. The legacy
single token migrates to an agent named "default" — pure, idempotent, no read
path ever writes; downgrade fails closed (an old binary sees token:"" and
autostart refuses). resolve_bearer folds over every agent with no early exit
and refuses anything that is not 64 lowercase hex. A revoke is visible on the
next request.

IDENTITY. From the bearer only; no tool takes from/as/agent_id. A caller may act
only on its own proposals, and a foreign id answers exactly like an unknown id.
Names are [a-z0-9][a-z0-9_-]{0,31}; reserved words and an adversarial table
(bidi override, ·, whitespace, 33 chars, "run?") are refused by test, because
the name is rendered in the approval bar and must not be able to forge it. The
bar reads "codex · run? ⌘⏎ approve · esc deny"; an external proposal with an
empty agent is not approvable by any key.

ASYNC PROPOSALS. run_command { command, wait_ms } returns within a clamped 25 s
with today's result or a proposal_id; await_decision polls, idempotent, pending
on expiry. There is NO approval timeout: a shown proposal waits as long as the
human takes. The proposal record owns the AgentRunGuard for exactly its
lifetime, released at every terminal state including a panic path; an invariant
test pins PROPOSALS non-terminal <=> AgentState.running. Store bounded at 64.
Abuse limits: 30 s global deny cooldown, 1 pending per agent, 4 total, and a
refusal never emits agent-propose.

Also: a read-only multi-line command block above the bar so a long proposal is
readable in full (closes a documented danger-gate limitation); hub_state, a
read-only IPC command tested to contain no 64-hex substring; protocol hygiene
(2025-11-25, MCP-Protocol-Version, no Mcp-Session-Id); client handshake replays.

Found by the adversarial pass and fixed: initialize disclosed run_command to
every caller regardless of scope; the "chord rule byte-identical" test matched
its own source line and could not fail; a denial cooldown could be outrun by a
caller that read the budget before the Esc landed; the four-surface drift test
ignored descriptions.

agent.rs: zero changed lines. enter_approves, agent_propose, agent_decide,
decision_stands, MIN_REVIEW byte-identical. pty_write_internal: 3 callers, the
write still lexically after the approval check.

183 -> 211 backend tests, 49 -> 55 frontend.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 41e930a9-3e45-4165-ad2a-25377295cd0e


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

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Add per-agent MCP identity and asynchronous command proposals

✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds per-agent tokens, scoped tools, registry commands, and fail-closed migration.
• Returns proposal IDs promptly without imposing timeouts on human approval.
• Names requesters, displays full commands, and limits proposal abuse.
Diagram

sequenceDiagram
    actor Client as MCP Client
    participant Server as HTTP Server
    participant Registry as Agent Registry
    participant RPC as RPC Dispatcher
    participant Store as Proposal Store
    participant Worker as Proposal Worker
    participant Bar as Approval Bar
    participant PTY as Terminal PTY

    Client->>Server: POST with bearer
    Server->>Registry: Resolve identity
    Registry-->>Server: Caller and scopes
    Server->>RPC: Scoped tool call
    RPC->>Store: Check budget and record
    RPC->>Worker: Start detached run
    Worker->>Bar: Show named command
    alt Human approves
        Bar-->>Worker: Approved
        Worker->>PTY: Write command
        PTY-->>Worker: Command result
        Worker->>Store: Settle result
    else Human denies
        Bar-->>Worker: Denied
        Worker->>Store: Settle denial
    end
    alt Decision within wait window
        Store-->>RPC: Final verdict
        RPC-->>Client: Tool result
    else Wait window expires
        Store-->>RPC: Pending proposal ID
        RPC-->>Client: Proposal ID
        Client->>Server: await_decision
        Server->>Store: Poll owned proposal
        Store-->>Client: Pending or verdict
    end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. SSE decision notifications
  • ➕ Pushes verdicts without repeated polling.
  • ➕ Can reduce client requests for long-lived proposals.
  • ➖ Several target clients have inconsistent streaming and timeout behavior.
  • ➖ Requires session or reconnection semantics that weaken the intentionally sessionless design.
  • ➖ Adds transport complexity around disconnected clients and retained verdicts.
2. Supervised async task queue
  • ➕ Bounds request and worker concurrency centrally.
  • ➕ Provides explicit cancellation, shutdown, and panic supervision.
  • ➕ Avoids creating an operating-system thread for every admitted request.
  • ➖ Requires replacing or wrapping the existing blocking tiny_http architecture.
  • ➖ Broadens an already security-sensitive milestone beyond identity and proposal semantics.
  • ➖ Offers limited immediate benefit while the approval slot permits only one active terminal run.

Recommendation: Keep the PR's polling-based proposal records and detached execution for this milestone: they preserve broad MCP client compatibility, avoid sessions, and cleanly separate client wait windows from human approval. Consider a supervised async executor later if admitted-request volume or shutdown behavior becomes operationally significant.

Files changed (9) +2854 / -266

Enhancement (5) +2699 / -204
lib.rsExpose agent commands and read-only hub state +16/-8

Expose agent commands and read-only hub state

• Adds '/mcp agent' commands to slash help and usage handling, registers the 'hub_state' IPC command, and updates drift tests for peeled-off MCP commands.

src-tauri/src/lib.rs

mcp_server.rsImplement scoped agent identities and asynchronous proposal handling +2339/-174

Implement scoped agent identities and asynchronous proposal handling

• Replaces the single bearer with a migratable per-agent registry, centralized tool scopes, immediate revocation, sanitized identity metadata, and client-specific onboarding output. Introduces bounded owned proposal records, 'await_decision', detached execution, 25-second wait caps, denial cooldowns, concurrency budgets, and read-only token-free hub state. Adds extensive unit and HTTP tests covering authorization, migration, lifecycle invariants, adversarial identities, client handshakes, revocation, and approval-gate preservation.

src-tauri/src/mcp_server.rs

main.cssStyle the full-command proposal panel +26/-0

Style the full-command proposal panel

• Adds a scrollable, wrapped, read-only proposal block above the AI bar so long commands remain visible before approval.

ui/assets/main.css

ai_bar.rsShow authenticated requesters and full proposal commands +205/-17

Show authenticated requesters and full proposal commands

• Renders the bearer-derived agent name in external approval prompts and prevents approval when identity is missing. Moves pending commands into a capped read-only display and loads registry names through token-free 'hub_state' IPC for completion. Adds tests for chord preservation, fail-closed approval, rendering fidelity, and backend cap synchronization.

ui/src/ai_bar.rs

complete.rsAdd completion support for MCP agent management +113/-5

Add completion support for MCP agent management

• Adds slash rows and positional completion for agent verbs and registered names, while avoiding suggestions for new names, scopes, or tokens. Strengthens cross-surface tests to compare agent command descriptions as well as forms.

ui/src/complete.rs

Tests (1) +5 / -1
theme.rsRequire proposal panel theme coverage +5/-1

Require proposal panel theme coverage

• Extends the theme completeness test to ensure the new approval proposal panel receives explicit themed styling.

ui/src/theme.rs

Documentation (3) +150 / -61
README.mdDocument per-agent MCP registration and asynchronous proposals +11/-5

Document per-agent MCP registration and asynchronous proposals

• Adds the agent registry commands to the user-facing command table and updates server setup examples. Explains named approval prompts and the new 'await_decision' polling workflow.

README.md

architecture.mdDescribe scoped identities and the proposal lifecycle +69/-23

Describe scoped identities and the proposal lifecycle

• Expands the MCP server architecture around bearer-derived callers, scoped tool authorization, detached proposal workers, bounded records, abuse limits, client timeout handling, and legacy token migration. It also documents the revised on-disk registry schema.

docs/architecture.md

danger-gate.mdUpdate the MCP server threat model and approval guarantees +70/-33

Update the MCP server threat model and approval guarantees

• Documents per-agent credentials, journal scope isolation, requester identity, denial cooldowns, proposal limits, and full-command rendering. Clarifies revocation behavior, asynchronous proposal lifetime, and remaining server-mode risks.

docs/danger-gate.md

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Fresh token holders read history 🐞 Bug ⛨ Security
Description
enable turns an empty registry into a legacy migration, causing migrate to grant the generated
default agent every scope instead of DEFAULT_SCOPES. On a fresh install or after the last agent
was revoked, /mcp serve on therefore creates a bearer that can call read_journal without the
explicit journal grant promised for new agents.
Code

src-tauri/src/mcp_server.rs[R186-189]

+        // Minted through the legacy field so `migrate` stays the ONE place that builds the
+        // `default` agent, and a fresh install gets exactly what 0.2.9 gave it.
        cfg.token = generate_token()?;
+        cfg = migrate(cfg);
Evidence
The scope constants exclude journal from DEFAULT_SCOPES, but migrate grants all entries in
SCOPES. enable deliberately generates a legacy token whenever the agent list is empty and
immediately passes it through that migration, while the threat-model documentation says only
migrated 0.2.9 credentials retain journal access.

src-tauri/src/mcp_server.rs[65-85]
src-tauri/src/mcp_server.rs[148-159]
src-tauri/src/mcp_server.rs[183-190]
docs/danger-gate.md[200-206]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Fresh and previously emptied registries create their first agent through the legacy migration path, which grants the sensitive `journal` scope intended only for actual legacy credentials.

## Fix Focus Areas
- src-tauri/src/mcp_server.rs[148-190]

## Recommended Fix
Reserve the all-scope migration for a token loaded from an existing legacy configuration. When `enable` creates a new first agent, construct it with `DEFAULT_SCOPES` directly, while preserving the legacy token byte-for-byte and with its historical scopes only when that token existed on disk.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Replacement agents receive old results 🐞 Bug ⛨ Security
Description
revoke_agent calls proposals::forget, which deliberately retains non-terminal proposals, while
proposal lookup and await_decision authorize access using only the reusable agent name stored on
each record. When that name is re-added, its replacement default-scoped token can enumerate
sequential process-wide proposal IDs, poll the revoked credential’s live proposal, and retrieve its
eventual verdict, command result, or output.
Code

src-tauri/src/mcp_server.rs[R1399-1403]

+    // A revoked name can be re-added (the natural thing to do for the same client), and
+    // `await_decision` answers by name — so without this the new token could walk the
+    // sequential ids and collect the previous holder's exit codes and output. Terminal records
+    // only: a live one still owns the approval slot and its bar is still on the user's screen.
+    proposals::forget(name);
Evidence
The revoke flow calls forget, which removes settled records but intentionally leaves live
proposals in place, and those records retain only an agent-name string as their ownership identity.
Proposal lookups compare that reusable name with a predictable sequential process-wide ID, while
await_decision exposes both pending state and settled results to any admitted caller with the
matching name; because revocation supports later re-registration under that name, the replacement
token can enumerate and retrieve the prior proposal after it settles.

src-tauri/src/mcp_server.rs[395-400]
src-tauri/src/mcp_server.rs[420-425]
src-tauri/src/mcp_server.rs[451-459]
src-tauri/src/mcp_server.rs[775-780]
src-tauri/src/mcp_server.rs[1385-1404]
src-tauri/src/mcp_server.rs[284-307]
src-tauri/src/mcp_server.rs[391-429]
src-tauri/src/mcp_server.rs[600-611]
src-tauri/src/mcp_server.rs[1392-1404]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Live proposals survive revocation and are owned only by a reusable agent name. Re-adding that name creates a replacement credential that can inherit and retrieve the revoked credential’s pending work, eventual verdict, command result, or output.

## Fix Focus Areas
- src-tauri/src/mcp_server.rs[284-429]
- src-tauri/src/mcp_server.rs[395-400]
- src-tauri/src/mcp_server.rs[451-459]
- src-tauri/src/mcp_server.rs[600-611]
- src-tauri/src/mcp_server.rs[1392-1404]

## Recommended Fix
Give each agent registration an immutable, opaque generation or instance identifier, and propagate it from bearer admission into `Caller` and proposal ownership. Store that identifier on every proposal and require it, together with the proposal ID, for polling and settlement checks. Re-adding the same display name must create a new generation; revoked live proposals may continue holding their execution guard or remain on the bar if required, but they must remain inaccessible to every replacement credential.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Hidden command tails remain approvable 🐞 Bug ⛨ Security
Description
proposal_block truncates commands after 4096 characters while explicitly retaining an unseen tail,
and the approval handler does not reject a truncated proposal. Built-in-agent commands bypass the
MCP command-length validation and are passed in full to agent_propose and then the PTY, so an
approved visible prefix can conceal destructive shell syntax in its tail.
Code

ui/src/ai_bar.rs[R110-117]

+/// Capped because the built-in agent's proposals come from a model and are bounded by
+/// nothing — the MCP path refuses a longer `command` outright. The cut is stated in the
+/// block, since what runs is still the whole thing.
+fn proposal_block(text: &str) -> String {
+    match text.char_indices().nth(MAX_COMMAND_CHARS) {
+        None => text.to_string(),
+        Some((i, _)) => format!("{}\n… cut at {MAX_COMMAND_CHARS} characters — the rest runs unseen", &text[..i]),
+    }
Evidence
The newly added UI hard-caps the proposal block and says the remaining text runs unseen, while its
key handler still approves based only on the normal approval chord. The backend rejects oversize
external commands, but the unchanged built-in path supplies arbitrary model text to the proposal
event and writes that complete text after approval.

ui/src/ai_bar.rs[110-124]
ui/src/ai_bar.rs[411-430]
src-tauri/src/mcp_server.rs[711-712]
src-tauri/src/agent.rs[325-328]
src-tauri/src/agent.rs[343-359]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The approval UI renders only the first 4096 characters of a long proposal but still permits approval of the complete command. The built-in agent has no matching command-size limit, so it can submit a command whose unseen suffix reaches the shell.

### Fix Focus Areas
- ui/src/ai_bar.rs[110-124]
- ui/src/ai_bar.rs[411-430]
- src-tauri/src/agent.rs[325-359]

### Recommended Fix
Ensure every approvable proposal is fully reviewable. Prefer rejecting or splitting built-in-agent commands above `MAX_COMMAND_CHARS` before emitting a proposal; alternatively, mark truncated proposals unapprovable and require an explicit paged full-text review that covers the exact command before enabling approval.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. Revoked tokens briefly remain valid 🐞 Bug ⛨ Security
Description
persist writes the changed configuration before replacing the in-memory AGENTS roster used for
authentication. A request admitted during that interval still resolves against the pre-revocation
roster, so a revoked bearer can start another request despite the promised next-request revocation
behavior.
Code

src-tauri/src/mcp_server.rs[R973-977]

+/// The ONE mutator of the registry: file first — it is the source of truth — then the live
+/// roster, so no path can write a revoke and forget the refresh. Callers hold CONFIG_WRITE.
+fn persist(path: &std::path::Path, cfg: &ServeConfig) -> Result<(), String> {
+    write_config(path, cfg)?;
+    set_agents(&cfg.agents);
Evidence
Authentication reads AGENTS for every request, but registry persistence performs file I/O before
calling set_agents. The listener remains active during this sequence, so another request can
authenticate against the stale roster between those two operations.

src-tauri/src/mcp_server.rs[931-942]
src-tauri/src/mcp_server.rs[967-978]
src-tauri/src/mcp_server.rs[1483-1486]
docs/danger-gate.md[214-218]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
A registry change is persisted to disk before the in-memory bearer-authentication roster is updated. Requests arriving between those operations authenticate against stale credentials, including credentials just revoked.

### Fix Focus Areas
- src-tauri/src/mcp_server.rs[931-942]
- src-tauri/src/mcp_server.rs[973-978]

### Recommended Fix
Use one synchronization boundary for roster persistence and admission. Hold the roster lock while writing the configuration and replacing the live roster, with the live roster changed only after a successful write; admission must acquire that same lock while resolving its bearer. This prevents an admission from observing the old roster after a successful revoke write while preserving the prior roster when persistence fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: 🧠 Deep: This is a security-sensitive, cross-cutting identity/authorization and asynchronous state-management change with substantial new logic across backend and UI, creating many independent opportunities for subtle defects.

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +186 to +189
// Minted through the legacy field so `migrate` stays the ONE place that builds the
// `default` agent, and a fresh install gets exactly what 0.2.9 gave it.
cfg.token = generate_token()?;
cfg = migrate(cfg);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Fresh token holders read history 🐞 Bug ⛨ Security

enable turns an empty registry into a legacy migration, causing migrate to grant the generated
default agent every scope instead of DEFAULT_SCOPES. On a fresh install or after the last agent
was revoked, /mcp serve on therefore creates a bearer that can call read_journal without the
explicit journal grant promised for new agents.
Agent Prompt
## Issue description
Fresh and previously emptied registries create their first agent through the legacy migration path, which grants the sensitive `journal` scope intended only for actual legacy credentials.

## Fix Focus Areas
- src-tauri/src/mcp_server.rs[148-190]

## Recommended Fix
Reserve the all-scope migration for a token loaded from an existing legacy configuration. When `enable` creates a new first agent, construct it with `DEFAULT_SCOPES` directly, while preserving the legacy token byte-for-byte and with its historical scopes only when that token existed on disk.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +1399 to +1403
// A revoked name can be re-added (the natural thing to do for the same client), and
// `await_decision` answers by name — so without this the new token could walk the
// sequential ids and collect the previous holder's exit codes and output. Terminal records
// only: a live one still owns the approval slot and its bar is still on the user's screen.
proposals::forget(name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. Replacement agents receive old results 🐞 Bug ⛨ Security

revoke_agent calls proposals::forget, which deliberately retains non-terminal proposals, while
proposal lookup and await_decision authorize access using only the reusable agent name stored on
each record. When that name is re-added, its replacement default-scoped token can enumerate
sequential process-wide proposal IDs, poll the revoked credential’s live proposal, and retrieve its
eventual verdict, command result, or output.
Agent Prompt
## Issue description
Live proposals survive revocation and are owned only by a reusable agent name. Re-adding that name creates a replacement credential that can inherit and retrieve the revoked credential’s pending work, eventual verdict, command result, or output.

## Fix Focus Areas
- src-tauri/src/mcp_server.rs[284-429]
- src-tauri/src/mcp_server.rs[395-400]
- src-tauri/src/mcp_server.rs[451-459]
- src-tauri/src/mcp_server.rs[600-611]
- src-tauri/src/mcp_server.rs[1392-1404]

## Recommended Fix
Give each agent registration an immutable, opaque generation or instance identifier, and propagate it from bearer admission into `Caller` and proposal ownership. Store that identifier on every proposal and require it, together with the proposal ID, for polling and settlement checks. Re-adding the same display name must create a new generation; revoked live proposals may continue holding their execution guard or remain on the bar if required, but they must remain inaccessible to every replacement credential.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +973 to +977
/// The ONE mutator of the registry: file first — it is the source of truth — then the live
/// roster, so no path can write a revoke and forget the refresh. Callers hold CONFIG_WRITE.
fn persist(path: &std::path::Path, cfg: &ServeConfig) -> Result<(), String> {
write_config(path, cfg)?;
set_agents(&cfg.agents);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

4. Revoked tokens briefly remain valid 🐞 Bug ⛨ Security

persist writes the changed configuration before replacing the in-memory AGENTS roster used for
authentication. A request admitted during that interval still resolves against the pre-revocation
roster, so a revoked bearer can start another request despite the promised next-request revocation
behavior.
Agent Prompt
### Issue description
A registry change is persisted to disk before the in-memory bearer-authentication roster is updated. Requests arriving between those operations authenticate against stale credentials, including credentials just revoked.

### Fix Focus Areas
- src-tauri/src/mcp_server.rs[931-942]
- src-tauri/src/mcp_server.rs[973-978]

### Recommended Fix
Use one synchronization boundary for roster persistence and admission. Hold the roster lock while writing the configuration and replacing the live roster, with the live roster changed only after a successful write; admission must acquire that same lock while resolving its bearer. This prevents an admission from observing the old roster after a successful revoke write while preserving the prior roster when persistence fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread ui/src/ai_bar.rs
Comment on lines +110 to +117
/// Capped because the built-in agent's proposals come from a model and are bounded by
/// nothing — the MCP path refuses a longer `command` outright. The cut is stated in the
/// block, since what runs is still the whole thing.
fn proposal_block(text: &str) -> String {
match text.char_indices().nth(MAX_COMMAND_CHARS) {
None => text.to_string(),
Some((i, _)) => format!("{}\n… cut at {MAX_COMMAND_CHARS} characters — the rest runs unseen", &text[..i]),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

3. Hidden command tails remain approvable 🐞 Bug ⛨ Security

proposal_block truncates commands after 4096 characters while explicitly retaining an unseen tail,
and the approval handler does not reject a truncated proposal. Built-in-agent commands bypass the
MCP command-length validation and are passed in full to agent_propose and then the PTY, so an
approved visible prefix can conceal destructive shell syntax in its tail.
Agent Prompt
### Issue description
The approval UI renders only the first 4096 characters of a long proposal but still permits approval of the complete command. The built-in agent has no matching command-size limit, so it can submit a command whose unseen suffix reaches the shell.

### Fix Focus Areas
- ui/src/ai_bar.rs[110-124]
- ui/src/ai_bar.rs[411-430]
- src-tauri/src/agent.rs[325-359]

### Recommended Fix
Ensure every approvable proposal is fully reviewable. Prefer rejecting or splitting built-in-agent commands above `MAX_COMMAND_CHARS` before emitting a proposal; alternatively, mark truncated proposals unapprovable and require an explicit paged full-text review that covers the exact command before enabling approval.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant