Repository navigation
fix(gateway): enforce the session permission mode on every Gateway tool call - #202941
Conversation
…ol call The Gateway applied a session's permission mode only to restricted senders, so an owner's Claude CLI chat in a bounded mode read files anywhere through OpenClaw's own tools. The Gateway runs those tools, so it now enforces the mode for every caller.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesApplies a session’s permission policy to Gateway-managed tools for every caller, including unrestricted owners using CLI chats. Example: An owner’s Claude CLI chat uses workspace mode and requests outside.txt outside its workspace.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR repairs a current Gateway permission-boundary failure with a focused change and supplied live proof; no introduced correctness or security defect was found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI MCP calls and authenticated HTTP tool invocations enter the shared Gateway resolver, which passes session policy into existing tool factories and returns policy-constrained tools. flowchart TD
A[CLI MCP request] --> C[Gateway tool resolver]
B[HTTP tool invocation] --> C
D[Prepared session permission policy] --> C
C --> E[Existing tool factories]
E --> F[Filesystem and execution policy]
F --> G[Tool result or refusal]
Technical reviewBest possible solution: Land the focused shared-resolver repair after required checks pass, keeping native CLI mediation in its existing stacked follow-up. Do we have a high-confidence way to reproduce the issue? Current-main source shows the policy being discarded for unrestricted owners, and the PR supplies a matching real CLI before/after reproduction; this review executed no target code. Is this the best way to solve the issue? This is the smallest complete Gateway repair: pass the already-prepared session policy into existing factories and align workspace selection, with one meaningful boundary regression and no competing implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 743062e30ff5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -1, Tests +30, Docs +2. Total +31 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 21, 2026, 12:28 AM ET / 05:28 UTC. |
|
Landed. A chat's permission mode now bounds OpenClaw's own tools on every runtime: the Gateway applies the session's policy to every caller, not only restricted senders, so a Claude CLI chat in a bounded mode can no longer read outside its sessionRoot through |
…202945) ## What Problem This Solves After #202941 the Gateway bounds OpenClaw's tools to a session's permission mode on every runtime. A CLI backend that keeps its own native tools still ignored the mode: Gemini CLI (its native file tools are never mediated) and a Claude CLI chat placed on a node (it keeps Claude's native tools). A Read only / Ask me / Auto-review chat on those routes could read and write anywhere through the CLI's own tools. ## Why This Change Was Made The CLI tool policy already has one owner for "this run must use only Gateway-mediated tools": the mediation path used for `tools.fs.workspaceOnly`, restricted senders and delegated runs. A bounded session mode now joins that list for backends that are not already mediated: - A backend that can run on the mediated surface (Gemini CLI with exact tool support) does so, and the Gateway enforces the mode. - A run that cannot be mediated (node-placed Claude, a backend without exact tools or the Gateway MCP bridge) is refused before any CLI or node I/O: `CLI backend <id> uses its own tools here and cannot keep this chat's <mode> permissions. Change this chat to Full access, or choose another runtime.` - Full access and sessions with no mode are unchanged. Ordinary Claude CLI turns are already mediated and unchanged. No existing chat on our deployments has a bounded mode on these routes (Peanutto: 64 Claude CLI chats, none node-placed, all mode unset; team-metal: none). ## Evidence - `prepare-tool-policy.delegation.test.ts`: a Gemini CLI turn with a `workspace` mode gets the mediated surface; a node-placed Claude turn with that mode is refused with the next step; `full` and unset keep the native surface. The two new mode cases fail on #202941's head and pass here. - Real product, tier source (`ocx src`), isolated Gateway, Claude CLI agent, caller with full operator scopes: | | #202941 head | This branch | |---|---|---| | Node-placed chat (`execHost: node`) in `workspace` mode | dispatched to the node (no node present: `Paired node needs claude-cli-skills-v1…`) | refused before dispatch: `CLI backend claude-cli uses its own tools here and cannot keep this chat's workspace permissions. Change this chat to Full access, or choose another runtime.` | | Ordinary chat in `workspace` mode, read inside the workspace | `FORK-READ-OK 7f3a` | `FORK-READ-OK 7f3a` | Not proven live: Gemini CLI (not installed on the test host); covered by the unit test above. Co-authored-by: Ayaan Zaidi <[email protected]>
…ls (#202957) ## What Problem This Solves #202945 added a second refusal path to the CLI tool policy: a bounded session mode on a CLI backend that keeps its own native tools (Gemini CLI, a node-placed Claude CLI chat) either forced the mediated surface or refused the turn. No chat on our deployments hits that case (Peanutto: 64 Claude CLI chats, none node-placed, none with a mode; team-metal: none), and it added a rule beside the one owner we want. ## Why This Change Was Made One rule: whoever runs a tool enforces the mode for it. The Gateway enforces the session mode on OpenClaw's own tools on every runtime (#202941, unchanged). A CLI backend's own native tools follow that CLI's permission controls; `docs/gateway/permission-modes.md` now says so instead of encoding a refusal. ## Changes - Reverts #202945 (`prepare-tool-policy.ts` back to its prior conditions, its three test cases removed). - One docs sentence naming Gemini CLI file tools and node-placed Claude CLI as following the CLI's own controls. Production: +1 −14. Tests: −35. ## Evidence - Pure revert of 8fdae41 plus docs; the code is byte-identical to its pre-#202945 state, which ran on `main` with green CI. - #202941's Gateway enforcement and its regression test are untouched. Co-authored-by: Ayaan Zaidi <[email protected]>
…ol call (openclaw#202941) ## What Problem This Solves A chat set to a permission mode (Read only, Ask me, Auto-review) bounds file tools to its `sessionRoot` on the built-in runtime. On a Claude CLI chat it did not: the CLI calls OpenClaw's own tools through the Gateway (`mcp__openclaw__read` and friends), and the Gateway applied the session's mode only to restricted senders. An owner's Claude CLI chat in `workspace` mode read files anywhere on the host. ## Why This Change Was Made The Gateway runs these tools, so it owns the boundary. `resolveGatewayScopedTools` now applies the session's permission policy for every caller instead of only `inheritedToolPolicySource === "sender"` (that scope came from openclaw#165418, which kept "ordinary owner/profile authority unchanged"; nothing else relies on owners being unbounded). The prepared session workspace now also applies when the session has a mode, so relative paths resolve inside the same root the policy bounds. Rule, now in `docs/gateway/permission-modes.md`: whoever runs a tool enforces the mode for it. The Gateway does for OpenClaw's tools on every runtime; Codex does for its own tools through its sandbox; host-only harnesses with their own tools (Muse, ACP) keep needing Full access. This replaces the paragraph from openclaw#202659 that said CLI chats use the CLI's own controls. A new sentence states that modes bound file tools and pick the exec reviewer; exec is not confined to `sessionRoot` unless the runtime sandboxes commands. Effects: - Sessions with no mode (the policy is undefined) are unchanged: cron, Skill Workshop, completion handoffs, subagents without a mode. - Owner `POST /tools/invoke` on a mode-set session is bounded the same way (same resolver, already passed the policy). - Subagent attachment roots stay readable: the Gateway builds tools through the same assembly that adds `subagentAttachmentRootForRun`. ## Evidence - `src/gateway/tool-resolution.test.ts`: an owner's loopback `read` on a `read-only` session refuses a path outside the root and lists no `write`; with no mode it reads. Red on the merge base (`expected '{"content":[{"type":"text","text":"ou…' to contain 'escapes'`), green here. - Real product, tier source (`ocx src`), isolated Gateway, a Claude CLI agent and a built-in ChatGPT agent, chat set to `permissionMode: "workspace"`, caller with full operator scopes, asked to read a file outside the workspace: | | Merge base | This branch | |---|---|---| | Claude CLI | read it: `OUTSIDE-SECRET 91c2` | refused: `Path escapes sandbox root (…/workspace): …/outside.txt` | | Built-in | refused, same error | refused, same error | Exec on that Claude CLI chat is unchanged by this PR (both: `exec denied: Headless runs cannot wait for interactive exec approval … security=allowlist ask=on-miss`), while the built-in chat's exec goes through the auto-reviewer; that difference predates this change and is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#202945) ## What Problem This Solves After openclaw#202941 the Gateway bounds OpenClaw's tools to a session's permission mode on every runtime. A CLI backend that keeps its own native tools still ignored the mode: Gemini CLI (its native file tools are never mediated) and a Claude CLI chat placed on a node (it keeps Claude's native tools). A Read only / Ask me / Auto-review chat on those routes could read and write anywhere through the CLI's own tools. ## Why This Change Was Made The CLI tool policy already has one owner for "this run must use only Gateway-mediated tools": the mediation path used for `tools.fs.workspaceOnly`, restricted senders and delegated runs. A bounded session mode now joins that list for backends that are not already mediated: - A backend that can run on the mediated surface (Gemini CLI with exact tool support) does so, and the Gateway enforces the mode. - A run that cannot be mediated (node-placed Claude, a backend without exact tools or the Gateway MCP bridge) is refused before any CLI or node I/O: `CLI backend <id> uses its own tools here and cannot keep this chat's <mode> permissions. Change this chat to Full access, or choose another runtime.` - Full access and sessions with no mode are unchanged. Ordinary Claude CLI turns are already mediated and unchanged. No existing chat on our deployments has a bounded mode on these routes (Peanutto: 64 Claude CLI chats, none node-placed, all mode unset; team-metal: none). ## Evidence - `prepare-tool-policy.delegation.test.ts`: a Gemini CLI turn with a `workspace` mode gets the mediated surface; a node-placed Claude turn with that mode is refused with the next step; `full` and unset keep the native surface. The two new mode cases fail on openclaw#202941's head and pass here. - Real product, tier source (`ocx src`), isolated Gateway, Claude CLI agent, caller with full operator scopes: | | openclaw#202941 head | This branch | |---|---|---| | Node-placed chat (`execHost: node`) in `workspace` mode | dispatched to the node (no node present: `Paired node needs claude-cli-skills-v1…`) | refused before dispatch: `CLI backend claude-cli uses its own tools here and cannot keep this chat's workspace permissions. Change this chat to Full access, or choose another runtime.` | | Ordinary chat in `workspace` mode, read inside the workspace | `FORK-READ-OK 7f3a` | `FORK-READ-OK 7f3a` | Not proven live: Gemini CLI (not installed on the test host); covered by the unit test above. Co-authored-by: Ayaan Zaidi <[email protected]>
…ls (openclaw#202957) ## What Problem This Solves openclaw#202945 added a second refusal path to the CLI tool policy: a bounded session mode on a CLI backend that keeps its own native tools (Gemini CLI, a node-placed Claude CLI chat) either forced the mediated surface or refused the turn. No chat on our deployments hits that case (Peanutto: 64 Claude CLI chats, none node-placed, none with a mode; team-metal: none), and it added a rule beside the one owner we want. ## Why This Change Was Made One rule: whoever runs a tool enforces the mode for it. The Gateway enforces the session mode on OpenClaw's own tools on every runtime (openclaw#202941, unchanged). A CLI backend's own native tools follow that CLI's permission controls; `docs/gateway/permission-modes.md` now says so instead of encoding a refusal. ## Changes - Reverts openclaw#202945 (`prepare-tool-policy.ts` back to its prior conditions, its three test cases removed). - One docs sentence naming Gemini CLI file tools and node-placed Claude CLI as following the CLI's own controls. Production: +1 −14. Tests: −35. ## Evidence - Pure revert of edc2e97 plus docs; the code is byte-identical to its pre-openclaw#202945 state, which ran on `main` with green CI. - openclaw#202941's Gateway enforcement and its regression test are untouched. Co-authored-by: Ayaan Zaidi <[email protected]>
…ol call (#202941) A chat set to a permission mode (Read only, Ask me, Auto-review) bounds file tools to its `sessionRoot` on the built-in runtime. On a Claude CLI chat it did not: the CLI calls OpenClaw's own tools through the Gateway (`mcp__openclaw__read` and friends), and the Gateway applied the session's mode only to restricted senders. An owner's Claude CLI chat in `workspace` mode read files anywhere on the host. The Gateway runs these tools, so it owns the boundary. `resolveGatewayScopedTools` now applies the session's permission policy for every caller instead of only `inheritedToolPolicySource === "sender"` (that scope came from #165418, which kept "ordinary owner/profile authority unchanged"; nothing else relies on owners being unbounded). The prepared session workspace now also applies when the session has a mode, so relative paths resolve inside the same root the policy bounds. Rule, now in `docs/gateway/permission-modes.md`: whoever runs a tool enforces the mode for it. The Gateway does for OpenClaw's tools on every runtime; Codex does for its own tools through its sandbox; host-only harnesses with their own tools (Muse, ACP) keep needing Full access. This replaces the paragraph from #202659 that said CLI chats use the CLI's own controls. A new sentence states that modes bound file tools and pick the exec reviewer; exec is not confined to `sessionRoot` unless the runtime sandboxes commands. Effects: - Sessions with no mode (the policy is undefined) are unchanged: cron, Skill Workshop, completion handoffs, subagents without a mode. - Owner `POST /tools/invoke` on a mode-set session is bounded the same way (same resolver, already passed the policy). - Subagent attachment roots stay readable: the Gateway builds tools through the same assembly that adds `subagentAttachmentRootForRun`. - `src/gateway/tool-resolution.test.ts`: an owner's loopback `read` on a `read-only` session refuses a path outside the root and lists no `write`; with no mode it reads. Red on the merge base (`expected '{"content":[{"type":"text","text":"ou…' to contain 'escapes'`), green here. - Real product, tier source (`ocx src`), isolated Gateway, a Claude CLI agent and a built-in ChatGPT agent, chat set to `permissionMode: "workspace"`, caller with full operator scopes, asked to read a file outside the workspace: | | Merge base | This branch | |---|---|---| | Claude CLI | read it: `OUTSIDE-SECRET 91c2` | refused: `Path escapes sandbox root (…/workspace): …/outside.txt` | | Built-in | refused, same error | refused, same error | Exec on that Claude CLI chat is unchanged by this PR (both: `exec denied: Headless runs cannot wait for interactive exec approval … security=allowlist ask=on-miss`), while the built-in chat's exec goes through the auto-reviewer; that difference predates this change and is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit a1599a4) Release adaptation: Insert the enforcement paragraphs because the stable baseline lacks the earlier CLI paragraph; retain stable-only guidance and clarify the native CLI distinction from #202957. Companions: #202945/#202957 runtime changes cancel out (baseline-equivalent); #202957 documentation distinction is included here. #202306 is a separate project-move feature, not applicable. Neither #202659 CLI forking nor the adjacent sharing, file-write, role, and routing changes are dependencies. Co-authored-by: RomneyDa <[email protected]>
Plugin session forks (`runForkedTurn`, `forkSession`; for example Better Prompt and Skill Workshop reviews) always ran on the built-in runtime. On a Claude CLI chat signed in with a Claude subscription:
- With only the CLI's own `claude` login, `runForkedTurn` failed with `No API key found for provider "claude-cli"`.
- With a Claude subscription token stored in OpenClaw, `runForkedTurn` sent the token to the Anthropic API directly, which bills metered extra usage instead of the plan (`cliBackendDispatch` notes in `run/params.ts`).
- `forkSession` refused every CLI runtime: `Session forks are not supported for CLI runtime claude-cli.`
OpenClaw already has one owner for "run this embedded run on the subscription CLI": `cliBackendDispatch: "subscription-auth"` (Active Memory's recall uses it). The fork owner opts into it; no new path:
- `runSessionFork` sets `cliBackendDispatch: "subscription-auth"`. Eligibility is unchanged: subscription (oauth/token) or unresolvable credentials go to the CLI; API keys keep the request replay and its prompt cache.
- Dispatch accepts the fork's in-memory conversation (`sessionManager`), and sends the CLI only the tools that may execute (`toolExecutionAllow`; an empty list is a tool-free run).
- Dispatch now picks the CLI account the way a new CLI session does. Before, it passed only an explicit pin, so a stored Claude token never reached the CLI (`Not logged in · Please run /login`); Active Memory recalls had the same gap.
- Runs that grant the plugin's own tools or set `maxTokens` keep the direct route: neither reaches a CLI process.
- Dispatch carries the run's policy facts to the CLI: a run under another session's policy (a fork's `sandboxSessionKey`) passes that session's entry, the requester fields and `internal_system` provenance into the CLI's Gateway tool grant, so restricted-sender limits apply to the fork as to the chat's own turns.
Accepted: a CLI fork starts a fresh CLI session with the conversation as context, so it does not reuse the chat's cache, and each fork leaves one Claude session file under `~/.claude/projects`, as Active Memory's CLI recalls already do. The source chat's native session is never resumed or written.
Permission modes (maintainer decision, now in `docs/gateway/permission-modes.md`): the `sessionRoot` boundary is enforced on the built-in runtime; CLI-backed chats use the CLI's own controls, and owner turns' Gateway tools are not limited to `sessionRoot`. Live, on a Claude CLI chat in `workspace` mode, an ordinary turn and a fork both read a file outside the workspace through `mcp__openclaw__read`, and the same chat on the built-in runtime refuses both with `Path escapes sandbox root`. A CLI fork therefore has the same file access as the chat's own CLI turns.
Not covered: Gemini CLI on a Google login (OpenClaw cannot limit its tools under OAuth), and harnesses that own their login with no limited one-shot turn (Copilot, Muse, `acp-*`).
Real product, tier source (`ocx src`), isolated foreground Gateway, no API key in the environment or auth store; profiles: Claude subscription setup token, ChatGPT OAuth, Grok OAuth. Each chat: one turn ("Remember PELICAN-42"), then forks through a probe plugin.
| Route | `runForkedTurn` `[read, ls]` | `forkSession` | `runForkedTurn` cache read |
|---|---|---|---|
| `claude-cli`, Claude token | `PELICAN-42 \| FORK-READ-OK 7f3a` (dispatched to Claude CLI) | `PELICAN-42` | 6,985 |
| ChatGPT OAuth, built-in | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (cache read 9,856) | 10,112 |
| Codex app-server | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (19,584) | 8,704 |
| Grok OAuth | `PELICAN-42 \| FORK-READ-OK 7f3a` | `PELICAN-42` (1,152) | 1,152 |
- `main` on the same Claude chat: `runForkedTurn` ran on the Anthropic API with the token (cache read 0, cache write 23,872), `forkSession` refused.
- Every route: source transcript hash, message count and native binding unchanged; the Claude source session file holds only the chat's own turn.
- Better Prompt 0.2.2 (`start` → `take` through `plugins.sessionAction`) produced an improved prompt on the Claude CLI chat and on the ChatGPT chat.
- Dispatch tests: a fork runs on the CLI with only its own tools from its in-memory session; plugin tool grants and output caps keep the passthrough.
Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit b7bf937)
Release adaptation: retain staged Gateway permission-mode documentation and enforcement; omit the superseded upstream documentation exception.
Companions: #202941 and #202646 are present-equivalent (9ec8d08 and 087c816); #201554 is staged as 5647120. #202957 is not applicable (reverts a separate native-tools path). #204219, #203999, #203901, #203919, #203601 and #203271 are independent prewarm, lifecycle, recovery, review or default-routing changes; not required for the selected fork path.
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 8a592a33b7866a1306c60468e4aaf2c9fb23a93f)
…ol call (#202941) Baseline adaptation: Enforce the session policy at the Gateway tool owner for owner and restricted caller paths; use the existing prepared workspace root when available. (cherry picked from commit a1599a4) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
A chat set to a permission mode (Read only, Ask me, Auto-review) bounds file tools to its
sessionRooton the built-in runtime. On a Claude CLI chat it did not: the CLI calls OpenClaw's own tools through the Gateway (mcp__openclaw__readand friends), and the Gateway applied the session's mode only to restricted senders. An owner's Claude CLI chat inworkspacemode read files anywhere on the host.Why This Change Was Made
The Gateway runs these tools, so it owns the boundary.
resolveGatewayScopedToolsnow applies the session's permission policy for every caller instead of onlyinheritedToolPolicySource === "sender"(that scope came from #165418, which kept "ordinary owner/profile authority unchanged"; nothing else relies on owners being unbounded). The prepared session workspace now also applies when the session has a mode, so relative paths resolve inside the same root the policy bounds.Rule, now in
docs/gateway/permission-modes.md: whoever runs a tool enforces the mode for it. The Gateway does for OpenClaw's tools on every runtime; Codex does for its own tools through its sandbox; host-only harnesses with their own tools (Muse, ACP) keep needing Full access. This replaces the paragraph from #202659 that said CLI chats use the CLI's own controls. A new sentence states that modes bound file tools and pick the exec reviewer; exec is not confined tosessionRootunless the runtime sandboxes commands.Effects:
POST /tools/invokeon a mode-set session is bounded the same way (same resolver, already passed the policy).subagentAttachmentRootForRun.Evidence
src/gateway/tool-resolution.test.ts: an owner's loopbackreadon aread-onlysession refuses a path outside the root and lists nowrite; with no mode it reads. Red on the merge base (expected '{"content":[{"type":"text","text":"ou…' to contain 'escapes'), green here.ocx src), isolated Gateway, a Claude CLI agent and a built-in ChatGPT agent, chat set topermissionMode: "workspace", caller with full operator scopes, asked to read a file outside the workspace:OUTSIDE-SECRET 91c2Path escapes sandbox root (…/workspace): …/outside.txtExec on that Claude CLI chat is unchanged by this PR (both:
exec denied: Headless runs cannot wait for interactive exec approval … security=allowlist ask=on-miss), while the built-in chat's exec goes through the auto-reviewer; that difference predates this change and is tracked separately.