Skip to content

fix(gateway): prevent cross-client system-agent session takeover - #111565

Merged
steipete merged 2 commits into
mainfrom
claude/fix-session-delegation-binding
Jul 19, 2026
Merged

steipete merged 2 commits into
mainfrom
claude/fix-session-delegation-binding

Conversation

@steipete

@steipete steipete commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a second authenticated client on a shared gateway could submit turns, approve a pending proposal, or reset another client's non-delegated system-agent chat when it knew or guessed that chat's session ID. Non-delegated sessions previously collapsed onto the same empty ownership key, so the existing session-binding check did not distinguish callers.

Threat model: two authenticated gateway clients, one known or guessable system-agent session ID, and no explicit host delegation. The second client must not learn session data or drive the first client's setup/configuration conversation.

Why This Change Was Made

Every system-agent session now has a required owner key. Explicit host-only delegation keeps its existing agent/session tuple so intentional cross-connection delegation continues to work; ordinary calls use the authenticated user identity, then the cryptographically verified paired-device identity, and finally the server-issued connection ID. Ownership is checked before any session message, approval response, or reset is processed, and mismatches return the existing redacted invalid-request response.

This is an additive gateway-internal ownership check. It does not change or version the gateway protocol, configuration, or persistent state.

User Impact

Control UI, CLI, and native clients can continue their own system-agent chats across legitimate reconnects, while another authenticated gateway client can no longer take over those sessions by replaying a session ID. Existing explicit regular-agent delegation behavior is unchanged.

Evidence

  • Regression reproduced before the fix: a different authenticated principal using the same session ID received a successful response and reached the original engine.
  • Focused ownership suite: 11/11 passed, covering cross-principal turn, proposal-decision, and reset rejection; redacted payloads; same-user reconnect; same-device reconnect; identityless fail-closed behavior; and unchanged explicit delegation.
  • Existing system-agent suite: 23/23 passed after the test-module split.
  • Remote Node 24 core typecheck: pnpm tsgo passed on Blacksmith Testbox (Actions run 29706113527).
  • Remote test typecheck: pnpm check:test-types passed on Blacksmith Testbox (Actions run 29706769628).
  • Targeted oxfmt, oxlint, and git diff --check passed.
  • Fresh autoreview on the rebased branch reported no accepted/actionable findings.
  • Exact-head CI passed on commit 1449bf2 (Actions run 29706935942). The first CI run caught implicit-any parameters in the new test helper and an unrelated TUI restart flake; the helper was typed in a follow-up commit, and both lanes passed on the corrected head.

AI-assisted: yes. The behavior, trust boundary, regression proof, and reconnect semantics were reviewed directly.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): prevent cross-client system-agent session takeover This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@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: 42f77a3a14

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +113 to +114
const connId = params.client?.connId?.trim();
return connId ? `connection:${connId}` : undefined;

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.

P1 Badge Preserve ownership across device-less CLI requests

When a caller has no authenticated user or device identity, binding the session to connId breaks multi-turn CLI conversations because callGatewayCli creates and stops a WebSocket for every RPC (src/gateway/call.ts:947-971,995-1013). This occurs for loopback token/password calls, where device identity is deliberately omitted (src/gateway/call.ts:486-512,1185-1190), and when identity loading fails in a restricted environment. runRemoteGatewayInferenceOnboarding sends the welcome and each reply through separate calls (src/commands/onboard-remote-gateway.ts:267-295), so its second turn gets a new connection key and is rejected as belonging to another caller. Use a stable authenticated owner for this flow or keep its connection alive instead of treating the per-request connection ID as session identity.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 19, 2026
@clawsweeper

clawsweeper Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 7:00 PM ET / 23:00 UTC.

Summary
The branch makes system-agent sessions require an owner key derived from explicit delegation, authenticated user, paired device, or gateway connection, and adds focused ownership tests.

PR surface: Source +35, Tests +275. Total +310 across 4 files.

Reproducibility: yes. from source: invoke the session once through a device-less loopback token/password CLI call, then send the next turn through its normal new WebSocket connection. The owner falls from the original connection ID to a different one and the session check rejects it.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Resolve the device-less reconnect contract and add a focused integration regression.
  • [P1] Attach redacted after-fix terminal output or runtime logs showing both a rejected second client and a successful multi-turn device-less CLI/onboarding flow.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body reports focused tests and CI, but the supplied evidence contains no inspectable after-fix live CLI/onboarding transcript, terminal output, recording, or redacted runtime log for the changed ownership path. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging as written breaks multi-turn system-agent conversations for loopback token/password CLI callers that have no stable authenticated-user or verified-device identity, because each RPC receives a new connection owner key.
  • [P1] Using a shared-secret-derived owner as a quick reconnect fix could reintroduce cross-client takeover if multiple clients legitimately share that credential; the stable-principal semantics need an explicit security decision.

Maintainer options:

  1. Preserve device-less CLI conversations before merge (recommended)
    Retain the secure cross-client rejection and add a single-connection client path plus regression proof for separate welcome and reply turns.
  2. Accept connection-scoped sessions only
    Merge only if maintainers intentionally accept that device-less loopback token/password clients must not resume a system-agent session after reconnecting.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Keep device-less callers connection-scoped; update remote onboarding or its gateway client to reuse one live WebSocket for the full system-agent conversation, add an integration regression for two turns, and retain cross-client rejection coverage.

Next step before merge

  • [P1] A maintainer must choose the stable identity versus single-connection lifecycle contract; this is not a safe automated repair because the wrong owner key can weaken the security boundary.

Maintainer decision needed

  • Question: For device-less loopback token/password CLI calls, should system-agent ownership remain connection-scoped with the client workflow reusing one socket, or is there a server-verifiable per-caller identity that can safely survive reconnects?
  • Rationale: A shared credential cannot safely become a caller identity without collapsing distinct clients back into the takeover condition; choosing the durable identity or connection-lifecycle contract is a security and product-boundary decision.
  • Likely owner: steipete — The unresolved decision is within the gateway session-ownership implementation introduced by these commits.
  • Options:
    • Reuse one gateway connection for the conversation (recommended): Keep the new connection-scoped fail-closed ownership rule and update the affected CLI/onboarding workflow to send its system-agent turns over one live connection.
    • Define a verified reconnect identity: Introduce a server-verifiable per-caller identity only if it distinguishes clients sharing the same token/password and is documented and tested across reconnects.

Security
Cleared: No credential handling, dependency, workflow, or supply-chain expansion was found; the blocking concern is a compatibility regression caused by the new security check.

Review findings

  • [P1] Preserve device-less CLI ownership across its next RPC — src/gateway/server-methods/system-agent.ts:112-118
Review details

Best possible solution:

Keep unidentifiable callers connection-bound for security, then make the affected onboarding/CLI conversation reuse one authenticated gateway connection across its system-agent turns; add an integration regression that proves both cross-client rejection and the device-less multi-turn path.

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

Yes, from source: invoke the session once through a device-less loopback token/password CLI call, then send the next turn through its normal new WebSocket connection. The owner falls from the original connection ID to a different one and the session check rejects it.

Is this the best way to solve the issue?

No. Binding unidentifiable clients to connId is a sound fail-closed default, but the PR must preserve the existing multi-turn caller lifecycle by reusing that connection or by using a genuinely server-verifiable per-caller identity.

Full review comments:

  • [P1] Preserve device-less CLI ownership across its next RPC — src/gateway/server-methods/system-agent.ts:112-118
    connId is new for every callGatewayCli RPC, while loopback token/password calls may intentionally have neither authenticatedUserId nor a device ID. Remote onboarding sends the welcome and follow-up turns through separate calls, so the follow-up is rejected as another owner. Keep this fallback fail-closed, but reuse one connection for the conversation or provide a server-verifiable per-caller identity.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.

Label justifications:

  • P1: The patch addresses a real gateway session-control security boundary but currently regresses a legitimate multi-turn CLI workflow.
  • merge-risk: 🚨 compatibility: Existing device-less shared-secret CLI and remote-onboarding flows can lose access to their own active system-agent session after a normal per-RPC reconnect.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports focused tests and CI, but the supplied evidence contains no inspectable after-fix live CLI/onboarding transcript, terminal output, recording, or redacted runtime log for the changed ownership path. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +35, Tests +275. Total +310 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 41 6 +35
Tests 2 369 94 +275
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 410 100 +310

What I checked:

  • Connection-bound fallback changes legitimate CLI behavior: The new owner resolver falls back to connection:${connId} when neither authenticated user nor paired device identity is available; a later request on a new WebSocket therefore cannot access the same system-agent session. (src/gateway/server-methods/system-agent.ts:113, 42f77a3a140a)
  • Existing CLI caller lifecycle conflicts with connection ownership: The recorded review evidence identifies callGatewayCli as creating and stopping a WebSocket for each RPC, while loopback token/password calls can intentionally omit device identity; remote onboarding sends welcome and subsequent turns through separate gateway calls. (src/gateway/call.ts:947, a0c3067b545b)
  • Prior blocker applies to the reviewed head: The latest completed ClawSweeper cycle reviewed head 1449bf2183ea0ba8ac59708d95dc9c981ce56efa and identified this exact P1: device-less CLI requests lose ownership across per-RPC connections. No later head is supplied. (src/gateway/server-methods/system-agent.ts:113, 1449bf2183ea)
  • The tests are handler-level mocked coverage, not an after-fix runtime flow: The new ownership suite mocks setup inference, fallback inference, transcript storage, and the session engine. It is useful regression coverage but does not demonstrate a device-less shared-secret CLI or remote-onboarding conversation surviving its next real RPC. (src/gateway/server-methods/system-agent-session-ownership.test.ts:1, 1449bf2183ea)
  • Repository policy treats fail-closed and fallback changes as compatibility-sensitive: The applicable repository policy requires upgrade-sensitive fallback and startup/workflow changes to preserve existing behavior or provide explicit proof; this branch introduces a new fail-closed outcome for an existing CLI path. (AGENTS.md:1, a0c3067b545b)

Likely related people:

  • steipete: The supplied history attributes both commits implementing and typing this system-agent ownership change to steipete; the required follow-up is in the same gateway ownership boundary. (role: gateway session-boundary author; confidence: medium; commits: 42f77a3a140a, 1449bf2183ea; files: src/gateway/server-methods/system-agent.ts, src/gateway/server-methods/system-agent-session-ownership.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-19T22:55:29.793Z sha 1449bf2 :: needs real behavior proof before merge. :: [P1] Preserve ownership across device-less CLI requests

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 19, 2026
@steipete
steipete merged commit 3c0f55b into main Jul 19, 2026
176 of 184 checks passed
@steipete
steipete deleted the claude/fix-session-delegation-binding branch July 19, 2026 23:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 20, 2026
…nclaw#111565)

* fix(gateway): bind system-agent sessions to callers

* test(gateway): type system-agent response helper
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…nclaw#111565)

* fix(gateway): bind system-agent sessions to callers

* test(gateway): type system-agent response helper
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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L 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