Skip to content

CLI gateway calls can poison local device scopes after read probes #95997

Closed

Description

@vincentkoc

Summary

Local CLI Gateway calls can leave the CLI paired device/token at a read-only scope after a read probe, then reject the next write-scoped CLI agent call with scope upgrade pending approval.

This is a stable-release blocker unless we decide the affected local state is intentionally expected, because the embedded fallback can hide the failure while the primary Gateway agent path is blocked.

Affected Surface

  • Local Gateway auth with shared token/password.
  • CLI clients using Gateway RPCs before an agent run, especially gateway health or other read-scoped probes followed by agent or another write-scoped call.
  • Observed during 2026.6.10 beta release smoke, but the failing path is present on current main.

Steps to Reproduce

  1. Start a local Gateway with token auth enabled.
  2. Run a CLI read-scoped RPC such as gateway health with the shared token.
  3. Run a CLI write-scoped agent command with the same local Gateway/session.
  4. Watch the Gateway close the primary agent connection with pairing scope-upgrade state.

Expected

Local CLI shared-token/password calls should not persist or reuse a durable read-scoped paired-device baseline that blocks later local CLI write/admin calls.

The security rule still needs to hold: an already-paired device reconnecting with a device identity must not silently widen scopes. Remote CLI/device-token paths should keep requiring explicit scope-upgrade approval.

Actual

The read probe can persist or reuse the CLI paired device at operator.read. A later agent run needs operator.write, so the server treats it as a paired-device scope upgrade and rejects the primary Gateway path.

Redacted audit shape:

security audit: device access upgrade requested reason=scope-upgrade auth=token roleFrom=operator roleTo=operator scopesFrom=operator.read scopesTo=operator.write client=cli

Observed client close:

1008 pairing required: device is asking for more scopes than currently approved

Root Cause

  • CLI calls derive least-privilege scopes per method. health maps to operator.read; agent maps to operator.write.
  • The client path carried a durable CLI device identity even when the caller already used loopback shared-token/password auth.
  • The server clears self-declared scopes for generic device-less shared-token clients, but had only a backend gateway-client exception for local shared-auth scope preservation.
  • Result: read-only CLI device state could become the baseline for later write-scoped local CLI calls.

Provenance

The broken behavior is the interaction between those pieces, not the scope-upgrade guard itself.

Fix Shape

  1. Keep paired-device scope-upgrade enforcement unchanged.
  2. Omit durable device identity for loopback CLI shared-token/password calls.
  3. Preserve declared scopes server-side only for local, non-browser CLI shared-token/password auth.
  4. Keep generic device-less shared-token/password clients scope-cleared.
  5. Add regression coverage for client identity omission, server scope preservation, and the stale read-scoped CLI baseline.

Activity

  1. self-assigned this
    on Jun 23, 2026
  2. clawsweeper commented on Jun 23, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 23, 2026, 3:59 PM ET / 19:59 UTC.

    Summary
    Keep open: this is a protected maintainer issue with a source-backed current-main bug and an open draft closing PR. Current main still only omits durable device identity for the backend gateway-client local path, while the linked fix commit is not contained in main or the latest release.

    Reproducibility: yes. at source level with high confidence: health resolves to operator.read, agent resolves to operator.write, current CLI shared-token calls still carry device identity, and the server preserves missing-device scopes only for backend gateway-client. I did not run the live Gateway sequence in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #95997
    Summary: This issue is the canonical tracker for the local CLI shared-auth read-probe poisoning path; the linked draft PR is the candidate fix, while broader CLI scope-upgrade deadlock reports remain adjacent rather than exact duplicates.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    No new repair job: this protected maintainer issue already has an open closing PR for the exact fix path.

    Security
    Needs attention: This issue is auth-boundary-sensitive; any fix must keep remote, browser, and device-token scope-upgrade approval intact.

    Review details

    Best possible solution:

    Review and land the linked draft PR, or an equivalent narrow fix, that omits durable device identity only for loopback CLI shared-token/password calls and preserves scope-upgrade enforcement elsewhere.

    Do we have a high-confidence way to reproduce the issue?

    Yes, at source level with high confidence: health resolves to operator.read, agent resolves to operator.write, current CLI shared-token calls still carry device identity, and the server preserves missing-device scopes only for backend gateway-client. I did not run the live Gateway sequence in this read-only review.

    Is this the best way to solve the issue?

    Yes, the linked PR's shape is the narrow maintainable fix: move only loopback CLI shared-token/password calls out of durable device identity and add a server-side CLI scope-preservation exception, without weakening remote or device-token scope-upgrade checks.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • I did not run a live local Gateway reproduction in this read-only review; the reproduction confidence comes from source inspection, current tests, and the linked PR's targeted evidence.
    • The repair is auth-boundary-sensitive: broadening the local CLI exception too far could weaken remote, browser-origin, or device-token scope-upgrade approval behavior.

    Codex review notes: model internal, reasoning high; reviewed against fcedd37067ec.

    Label changes

    Label changes:

    • add P1: The issue blocks the primary local Gateway agent path after common read-scoped CLI probes and was reported as a stable-release blocker.
    • add impact:security: The fix must preserve the paired-device scope-upgrade authorization boundary while changing local shared-auth behavior.
    • add impact:auth-provider: The bug is in Gateway token/password auth, durable device identity, and operator scope resolution for CLI calls.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.
    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-security-review: Current issue advisory state selects this label.

    Label justifications:

    • P1: The issue blocks the primary local Gateway agent path after common read-scoped CLI probes and was reported as a stable-release blocker.
    • impact:security: The fix must preserve the paired-device scope-upgrade authorization boundary while changing local shared-auth behavior.
    • impact:auth-provider: The bug is in Gateway token/password auth, durable device identity, and operator scope resolution for CLI calls.
    Evidence reviewed

    Security concerns:

    • [medium] Preserve scope-upgrade enforcement — src/gateway/server/ws-connection/message-handler.ts:1422
      The current bug is local CLI shared-auth poisoning, but the security rule in message-handler.ts intentionally prevents silent scope widening for already-paired devices and should remain covered by regression tests.
      Confidence: 0.88

    What I checked:

    Likely related people:

    • vincentkoc: Blame on the current central gateway call and handshake files points to Vincent Koc in this checkout, and the open closing PR is authored by the same person with a targeted fix for this behavior. (role: recent area contributor and current issue owner; confidence: high; commits: 3f2b205dde19, 40a422837bd2; files: src/gateway/call.ts, src/gateway/server/ws-connection/handshake-auth-helpers.ts, src/gateway/server/ws-connection/message-handler.ts)
    • fuller-stack-dev: Commit 65b460f carried forward the direct-local backend carve-out and nearby pending-reapproval diagnostics in the same gateway auth/pairing surface. (role: recent adjacent contributor; confidence: medium; commits: 65b460f2345a; files: src/gateway/server/ws-connection/message-handler.ts, src/gateway/server/ws-connection/handshake-auth-helpers.ts)
    • steipete: Commit b1117d9 extracted gateway client shared-token/device-token behavior, which is part of the client-side persistence boundary implicated here. (role: gateway client refactor contributor; confidence: medium; commits: b1117d98622f; files: src/gateway/client.ts, packages/gateway-client)
    • Devin Robison: Commit 81ebc7e introduced the silent reconnect scope-upgrade protection that this issue says must remain intact. (role: scope-upgrade guard introducer; confidence: medium; commits: 81ebc7e0344f; files: src/gateway/server/ws-connection/message-handler.ts, src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts)
    • Jacob Tomlinson: Commit d3d8e31 tightened backend scope-upgrade enforcement, which is adjacent to the backend-vs-CLI local shared-auth split. (role: backend scope-upgrade contributor; confidence: medium; commits: d3d8e316bd81; files: src/gateway/server/ws-connection/message-handler.ts, src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  3. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    on Jun 23, 2026
  4. locked as resolved and limited conversation to collaborators on Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.maintainerMaintainer-authored PR

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions