Skip to content

Gateway: preserve approved scope baseline during pairing - #58367

Closed
jacobtomlinson wants to merge 3 commits into
openclaw:mainfrom
jacobtomlinson:fix/fix-200
Closed

jacobtomlinson wants to merge 3 commits into
openclaw:mainfrom
jacobtomlinson:fix/fix-200

Conversation

@jacobtomlinson

Copy link
Copy Markdown
Contributor

Summary

  • preserves the approved operator scope baseline during silent pairing flows
  • requires explicit approval before a fresh shared-auth device gains newly requested operator scopes
  • adds regression coverage for fresh-device pairing and reconnect behavior

Changes

  • resolve silent pairing approver scopes from the paired device record instead of the requested scopes
  • add coverage for unpaired shared-auth devices requesting operator.admin and the explicit-approval follow-up path
  • adjust reconnect coverage to match the hardened approval flow and avoid leaked timeout rejections in the test harness

Validation

  • Ran pnpm test -- src/gateway/server.local-device-pairing-approval.test.ts src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts src/gateway/server/ws-connection/handshake-auth-helpers.test.ts
  • Ran pnpm check
  • Ran claude -p "/review" and addressed the non-actionable test feedback during validation

Notes

  • Incorporates earlier advisory-branch work from @smaeljaish771 with co-author credit preserved in commit history

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Mar 31, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bea84dbb3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR hardens the gateway's shared-auth device pairing flow by requiring explicit approval before any fresh (unpaired) device can gain operator scopes, and adds regression tests that confirm the new behavior. The security-relevant behavioral change is delivered entirely through shouldAllowSilentLocalPairing no longer accepting "not-paired" as a valid reason for silent pairing.

Key changes:

  • handshake-auth-helpers.ts: removes "not-paired" from the set of reasons that allow silent local pairing — this is the single change that forces all fresh devices through explicit approval.
  • message-handler.ts: refactors pairingStateAllowsRequestedAccess into two functions and adds a silentApprovalScopes guard inside the if (pairing.request.silent === true) block.
  • server.local-device-pairing-approval.test.ts: new file with solid regression coverage for the three fresh-device scenarios.
  • server.silent-scope-upgrade-reconnect.poc.test.ts: removes the watcher client and three race-condition tests (concurrent approval, rejection, supersession) that depended on the silent-pairing auto-approval path.

Notable concern: The if (pairing.request.silent === true) block in message-handler.ts is now unreachable dead code. shouldAllowSilentLocalPairing only returns true for reason === "scope-upgrade", but the call site unconditionally passes silent: false for scope-upgrades via the ternary reason === "scope-upgrade" ? false : allowSilentLocalPairing. The silentApprovalScopes scope-baseline fix that is the stated purpose of this PR therefore never executes. The actual security guarantee is correct, but the code as written is internally inconsistent and the silent-pairing branch (along with its race-condition test coverage) should be either cleaned up or reconnected.

Confidence Score: 4/5

  • Safe to merge from a security standpoint, but the stated scope-baseline fix is in unreachable dead code and the silent-pairing branch should be cleaned up before further development on that path.
  • The intended security behavior (fresh devices require explicit approval) is correctly enforced by the shouldAllowSilentLocalPairing change. However, the main stated fix — using the approved scope baseline instead of the requested scopes in silent pairing — is in a branch that pairing.request.silent can never enter. This leaves the code internally inconsistent: the guard exists but can never be reached, and the three removed race-condition tests provided coverage for that now-dead path. Score is 4 rather than 5 because the discrepancy between the stated fix and what actually executes warrants attention before the silent-pairing code is touched again.
  • src/gateway/server/ws-connection/message-handler.ts — the if (pairing.request.silent === true) block on lines 821–854 is dead code.

Comments Outside Diff (1)

  1. src/gateway/server/ws-connection/message-handler.ts, line 821-854 (link)

    Silent-pairing branch is now unreachable — the scope-baseline fix never executes

    The security fix described in this PR (silentApprovalScopes on line 822) lives inside if (pairing.request.silent === true), but that condition can never be true after this change.

    Here's why:

    allowSilentLocalPairing comes from shouldAllowSilentLocalPairing(...), which now only returns true when reason === "scope-upgrade". However, requestDevicePairing is called with:

    silent: reason === "scope-upgrade" ? false : allowSilentLocalPairing,
    • When reason === "scope-upgrade": silent is forced to false.
    • When reason !== "scope-upgrade": allowSilentLocalPairing is false (because shouldAllowSilentLocalPairing requires reason === "scope-upgrade"), so silent is also false.

    pairing.request.silent is therefore always false, and the entire block on lines 821-854 is dead code. The silentApprovalScopes variable, the approveDevicePairing auto-approval call, and the concurrent-approval fallback paths are never reached.

    The actual security guarantee — that fresh devices require explicit approval — is correctly delivered by changing shouldAllowSilentLocalPairing to reject "not-paired". But the stated "preserve approved scope baseline during silent pairing flows" fix is a no-op.

    This matters for maintainability: a developer who later re-enables silent pairing (e.g. by reverting the shouldAllowSilentLocalPairing change without touching the ternary) would assume the scope baseline guard is protecting them, but the ternary still forces silent: false, so the guard still won't execute.

    You likely want one of:

    • Remove the silent-pairing branch entirely (it's dead, and all three removed race-condition tests confirm it's no longer needed).
    • Or change the ternary to silent: allowSilentLocalPairing and keep the scope-baseline guard active for scope-upgrade reconnects.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server/ws-connection/message-handler.ts
Line: 821-854

Comment:
**Silent-pairing branch is now unreachable — the scope-baseline fix never executes**

The security fix described in this PR (`silentApprovalScopes` on line 822) lives inside `if (pairing.request.silent === true)`, but that condition can never be `true` after this change.

Here's why:

`allowSilentLocalPairing` comes from `shouldAllowSilentLocalPairing(...)`, which now only returns `true` when `reason === "scope-upgrade"`. However, `requestDevicePairing` is called with:
```ts
silent: reason === "scope-upgrade" ? false : allowSilentLocalPairing,
```
- When `reason === "scope-upgrade"`: `silent` is forced to `false`.
- When `reason !== "scope-upgrade"`: `allowSilentLocalPairing` is `false` (because `shouldAllowSilentLocalPairing` requires `reason === "scope-upgrade"`), so `silent` is also `false`.

`pairing.request.silent` is therefore always `false`, and the entire block on lines 821-854 is dead code. The `silentApprovalScopes` variable, the `approveDevicePairing` auto-approval call, and the concurrent-approval fallback paths are never reached.

The actual security guarantee — that fresh devices require explicit approval — is correctly delivered by changing `shouldAllowSilentLocalPairing` to reject `"not-paired"`. But the stated "preserve approved scope baseline during silent pairing flows" fix is a no-op.

This matters for maintainability: a developer who later re-enables silent pairing (e.g. by reverting the `shouldAllowSilentLocalPairing` change without touching the ternary) would assume the scope baseline guard is protecting them, but the ternary still forces `silent: false`, so the guard still won't execute.

You likely want one of:
- Remove the silent-pairing branch entirely (it's dead, and all three removed race-condition tests confirm it's no longer needed).
- Or change the ternary to `silent: allowSilentLocalPairing` and keep the scope-baseline guard active for scope-upgrade reconnects.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "Gateway: require approval for fresh loca..." | Re-trigger Greptile

@jacobtomlinson
jacobtomlinson requested a review from a team as a code owner March 31, 2026 12:41
@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up on the latest head that removes silent local pairing for fresh not-paired devices, adds explicit empty-scope regression coverage, and trims the now-obsolete silent-not-paired race tests.

@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jacobtomlinson

Copy link
Copy Markdown
Contributor Author

@greptile review

@jacobtomlinson
jacobtomlinson marked this pull request as draft April 2, 2026 13:16
@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open for maintainer handling: this protected draft changes a documented Gateway pairing/auth default, repeats a product-contract concern already called out on a closely related PR, and still lacks real behavior proof.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Yes, source-reproducible: current main allows direct-local not-paired silent pairing through shouldAllowSilentLocalPairing, and docs/tests lock in local auto-approval. I did not run a live Gateway repro in this read-only review.

Is this the best way to solve the issue?

No as-is. The safer solution is to preserve the shipped local default and add a maintainer-approved strict opt-in mode if the threat model changes.

Security review:

Security review cleared: No supply-chain, secret-handling, or new code-execution concern was found; the auth-policy compatibility impact is tracked as merge risk.

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-03-31T12:28:40Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is mock_only and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • steipete: Closed the closely related stricter-local-pairing PR as a product-contract change and authored recent paired-scope-baseline and silent-local-scope work in the affected path. (role: prior product-decision commenter and recent gateway pairing contributor; confidence: high; commits: 20b08f1a856d, 7f1b159c0391; files: src/gateway/server/ws-connection/message-handler.ts, src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts)
  • jacobtomlinson: Beyond authoring this PR, prior merged history shows Jacob worked on caller-scope forwarding and backend scope-upgrade boundaries in the affected Gateway pairing path. (role: adjacent auth/pairing contributor; confidence: high; commits: 4ee4960de233, d3d8e316bd81; files: src/gateway/server/ws-connection/message-handler.ts, src/infra/device-pairing.ts, src/gateway/server.silent-scope-upgrade-reconnect.poc.test.ts)
  • openperf: Authored the merged local loopback role-upgrade restoration that shares the same silent-local-pairing helper and preserves local-only convenience behavior. (role: sibling loopback pairing contributor; confidence: medium; commits: 51edd30bea98; files: src/gateway/server/ws-connection/handshake-auth-helpers.ts, src/infra/device-pairing.ts)

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

@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant