Repository navigation
fix(gateway): stop fabricating scope-upgrade requests on trusted-proxy reconnects - #129563
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
1a1e12a to
b6ba998
Compare
|
Codex review: needs real behavior proof before merge. Reviewed August 25, 2026, 8:28 PM ET / August 26, 2026, 00:28 UTC. ClawSweeper reviewWhat this changesThe PR narrows same-key trusted-proxy reconnects to their existing paired grant instead of creating and auto-approving a redundant scope-upgrade request. Regression provenancePossible regression — suspected (known regression link). No predecessor PR is attributed. Merge readiness⛔ Blocked until stronger real behavior proof is added - 6 items remain Keep open: the fast path still permits a paired-device revoke, replacement, or scope reduction to race session registration. Likely related people: steipete (high confidence). Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — step 1 Assertions:
How this fits togetherGateway WebSocket connects authenticate a trusted-proxy client, compare requested scopes with a paired-device grant, and then register the session. Genuine upgrades enter pairing approval; no-op reconnects should narrow without generating pairing writes or false audit warnings. flowchart TD
A[Browser reconnect] --> B[Trusted-proxy authentication]
B --> C[Paired device lookup]
C --> D{Existing grant covers access}
D -->|No| E[Pairing request and approval]
D -->|Yes| F[Narrow session scopes]
E --> G[Attach gateway session]
F --> G
Before merge
Findings
Agent review detailsSecurityNeeds attention: The new authorization fast path does not retain paired-device authority through final session attachment. PR surfaceSource +34, Tests +54, Docs 0. Total +88 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Revalidate the exact paired-device authority immediately before session registration, reject stale grants before I/O, and keep the reconnect policy on one canonical path. Do we have a high-confidence way to reproduce the issue? Yes from source: a revoke or replacement after the fast-path reread but before session attachment reaches later awaits without another paired-row check. Is this the best way to solve the issue? No; the recheck belongs at the final session-attachment boundary rather than before later metadata and profile work. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c1bab399abac. LabelsLabel justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
b6ba998 to
7f3f83e
Compare
|
Applied the review. Per-item status:
|
79f9f55 to
4d20d64
Compare
…y reconnects Same-key trusted-proxy reconnects whose auto-approvable scopes are already covered by the paired grant now narrow the session in place instead of running the pairing request/approve machinery: no pending-store writes and no false 'device access upgrade requested' / 'auto-approved' security-audit warns on every Control UI page load. The upgrade audit warn moved into requirePairing so it fires only when a pairing request is materialized. Durable widening (broadened deviceAutoApprove.scopes) and key-mismatch repairs keep the existing lanes.
…path Address ClawSweeper P1: the narrowing decision now rereads the authoritative paired row as the last await before returning, so a concurrent revoke, key replacement, or grant reduction fails closed into the pairing lane instead of riding the pre-plan snapshot. Extract the pairing approval-plan resolver into connect-pairing-approval-plan.ts to keep the authorization owner under the 700-line lint boundary.
4d20d64 to
8a1c594
Compare
|
Re-review finding "revalidate at the session-attachment boundary" — skip stated, with evidence:
The review's Live Verification FAIL is again the review harness's own 30-second command timeout while the suite was still booting; the suite passes locally (13/13) and in exact-head CI (green on 8a1c594). All previously actionable findings are applied (live-row revalidation as the last await, approval-plan module split) or skip-stated above; landing per review policy. |
|
Merged via squash.
|
…y reconnects (openclaw#129563) * fix(gateway): stop fabricating scope-upgrade requests on trusted-proxy reconnects Same-key trusted-proxy reconnects whose auto-approvable scopes are already covered by the paired grant now narrow the session in place instead of running the pairing request/approve machinery: no pending-store writes and no false 'device access upgrade requested' / 'auto-approved' security-audit warns on every Control UI page load. The upgrade audit warn moved into requirePairing so it fires only when a pairing request is materialized. Durable widening (broadened deviceAutoApprove.scopes) and key-mismatch repairs keep the existing lanes. * fix(gateway): revalidate the live paired grant in the reconnect fast path Address ClawSweeper P1: the narrowing decision now rereads the authoritative paired row as the last await before returning, so a concurrent revoke, key replacement, or grant reduction fails closed into the pairing lane instead of riding the pre-plan snapshot. Extract the pairing approval-plan resolver into connect-pairing-approval-plan.ts to keep the authorization owner under the 700-line lint boundary.
What Problem This Solves
On trusted-proxy gateways with
deviceAutoApproveenabled (e.g. team.openclaw.ai), every Control UI reconnect — page load, laptop wake, network flap — fabricated a device scope-upgrade round-trip: asecurity audit: device access upgrade requested reason=scope-upgradewarn, a pending pairing-store write, an instant same-key auto-approval (~6ms later, second store write), and atrusted-proxy browser device auto-approvedwarn. Nothing new was ever granted.Root cause chain:
operator.admin,operator.pairing) whenever it has no stored device-token scopes.gateway.rolesconfigured, the Gateway intentionally issues no device tokens to human operators, so the browser never learns its narrowed grant and re-requests the full set on every connect.The security-audit log on a busy team gateway reads as continuous privilege-escalation attempts by every user (admins included, since their
operator.admincomes fromidentityScopesand never lands on the device row). This is a doctrine-class recorded-fact bug: the audit entry implies operator intent that never existed.Why This Change Was Made
requirePairingnow short-circuits the deterministic case: for a same-key trusted-proxy scope-upgrade where the auto-approvable scope set is already covered by the existing paired grant, the session simply narrows to that grant — no pairing request, no store writes, no audit warns. Intent-driven widening stays ondevice.scopes.requestUpgrade; genuine durable widening (operator broadeneddeviceAutoApprove.scopesafter pairing) still flows through the existing request + auto-approve lane and still audits.The
device access upgrade requestedaudit warn moved from the call sites intorequirePairing, so it fires exactly when a pairing request is materialized — restoring the invariant that an audit entry corresponds to a real pending upgrade. The narrowed session set is(requested ∪ auto-approvable) ∩ pairedunder operator scope-implication semantics, so sessions never exceed the durable device grant, and owner-granted extras (e.g. a manually addedoperator.pairing) now survive reconnects instead of being clobbered to the config intersection.User Impact
scope-upgradeentries once again mean someone actually asked for elevation.identityScopes, role policies, or thex-openclaw-scopescap (still applied inresolveEffectiveConnectionScopes).docs/gateway/trusted-proxy-auth.mdrule 2 was stale (predates fix(gateway): auto-approve trusted-proxy same-key device scope upgrades #111916) and now describes actual same-key behavior.Evidence
narrows same-key reconnects without a pairing round-trip(src/gateway/server.auth.trusted-proxy-device-autoapprove.test.ts): second connect over-requesting admin+pairing succeeds with hello scopes narrowed to the paired grant, leaves no pending request, leaves the paired row untouched, and emits neither audit warn. Verified failing on pre-fix code (fails on the falsedevice access upgrade requestedwarn).server.auth.trusted-proxy-device-autoapprove.test.ts(13 passed, incl. the durable-widening same-key test),server-methods/device-scope-upgrade.test.ts(4 passed),server.auth.control-ui.test.ts(40 passed),node scripts/check-changed.mjsclean.After-fix final-effect proof (real Gateway harness)
Per the repo's real-behavior-proof gate, the mock-gateway harness (real in-process Gateway, real WebSocket handshake, real pairing store) covers the changed path:
operator.admin+operator.pairing; the connect succeeds and the hello reportsauth.scopes = ["operator.read","operator.write"](the paired grant), with zero pending pairing requests, an untouched paired row, and neitherdevice access upgrade requestednorauto-approvedaudit warn.ClawSweeper P1 (stale-authority race)
Applied: the fast path now rereads the authoritative paired row (
getPairedDevice) as the last await before the decision and validates key + role + auto-approve coverage against that live row; the return is synchronous after the read. The interleaved-revocation window itself is a microtask boundary not reachable deterministically from the black-box WS harness without a test-only seam (which repo policy forbids); the reachable end states are regression-covered and the ordering invariant is enforced and commented at the code site.resolvePairingApprovalPlanmoved toconnect-pairing-approval-plan.tsto keep the authorization owner under the 700-line boundary (move-only).