Skip to content

fix(security): cap delegated session tools - #150705

Closed
vincentkoc wants to merge 4 commits into
sec/fail-closed-delegated-tool-cap-v2from
sec/cap-delegated-session-tools
Closed

vincentkoc wants to merge 4 commits into
sec/fail-closed-delegated-tool-cap-v2from
sec/cap-delegated-session-tools

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

sessions_send currently starts receiving turns from the target's normal tool policy, so cross-agent, worker, CLI/MCP, and chained sends can gain tools absent from the sender.

Scope

  • Capture the source's exact final tool names after schema projection.
  • Carry that cap only through the trusted in-process agent-tool caller, with the source's live assertion.
  • Apply it as the receiving turn's toolsAllow; the target's own policy can only narrow it.
  • Reject transport, active-target, notify, watch, resume, and zero-timeout handoffs that cannot preserve the exact process-bound authority.
  • Include skill and worker-owned tool assembly without adding config, protocol, persistence, or a new policy stack.

This is the second and final slice replacing #144269, based on the original diagnosis by @pgondhi987. It is stacked on #150702 because delegated restart recovery must stop when the process-bound cap is lost.

Production LOC: +84 net; tests: +45 net.

Verification

  • pnpm dlx [email protected] --check on all changed files
  • git diff --check
  • Added focused capture and receiving-owner regression coverage
  • Direct Codex source check at openai/codex current origin/main: MCP server allow/deny shape is distinct from the native app-tool surface (codex-rs/config/src/mcp_types.rs), so OpenClaw's existing exact CLI availability gate remains the enforcement owner.

Scoped Vitest and structured autoreview await the same exact-head environment gate recorded on #150702.

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@vincentkoc vincentkoc self-assigned this Sep 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 17, 2026
@clawsweeper clawsweeper Bot added 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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 17, 2026, 4:07 AM ET / 08:07 UTC (Revision 3).

ClawSweeper review

What this changes

The PR carries a sending session’s exact tool permissions into receiving turns and rejects handoffs that cannot retain live sender authority.

Merge readiness

⛔ Blocked before merge - 7 items remain

This maintainer-owned security repair remains necessary on current main. The prior fixes improve enforcement, but a worker-receiver gap and an inconsistent advertised contract still block readiness.

Priority: P1
Reviewed head: 448c7d521ec9a1cb283b0a318d6486f001740b4b

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The repair is focused and materially improved, but a concrete worker enforcement gap and missing authority proof limit readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: the revised capture, receiving admission, and worker launch need observable allowed and sender-denied effects, plus rejection after source completion, cancellation, or replacement. Current tests stop at mocked projection or dispatch; the predecessor's valid filesystem/WebSocket traces exercise replaced machinery. Provide redacted terminal traces or logs, removing credentials, private endpoints, IP addresses, and personal data; update the PR body for re-review, or ask a maintainer for @clawsweeper re-review if needed.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: the revised capture, receiving admission, and worker launch need observable allowed and sender-denied effects, plus rejection after source completion, cancellation, or replacement. Current tests stop at mocked projection or dispatch; the predecessor's valid filesystem/WebSocket traces exercise replaced machinery. Provide redacted terminal traces or logs, removing credentials, private endpoints, IP addresses, and personal data; update the PR body for re-review, or ask a maintainer for @clawsweeper re-review if needed.
Evidence reviewed 10 items Pinned introduction and current PR state: The reviewed checkout is the original head 448c7d521ec9a1cb283b0a318d6486f001740b4b, with recorded parent 9a05f9eb338c84b5395c18bdd2afb62c821bd3c6. GitHub confirms the PR remains open, unmerged, MEMBER-authored, and stacked on sec/fail-closed-delegated-tool-cap-v2.
Current main still lacks session-send cap admission: Current main selects plugin-subagent or restored-cron allowlists at receiving dispatch; it does not consume sessionsSendToolsAllow or bind the sending session's assertion here. No merged replacement is established by the related-item context.
Prior findings checked against revised source: The revised branch intersects embedded outgoing session/spawn captures with toolExecutionAllow, selects exact CLI grant projection, and rejects capped ACP dispatch before backend execution. The earlier reviewed object 5fb43680dc430869c6c277e18a76e3240c378180 was unavailable locally, so unchanged-code continuity could not be established for newly identified concerns.
Findings 2 actionable findings [P1] [P1] Enforce the exact ceiling before launching a receiving worker
[P2] [P2] Stop advertising operations rejected by the capped send tool
Security Needs attention Worker receivers widen the sender's exact tool authority: Policy expansion adds apply_patch to a write-only transferred cap, and worker execution consumes that expanded grant without the local embedded execution gate.

How this fits together

Session-send tools ask the Gateway to run another session. The Gateway selects the receiving runtime, whose tool assembly must intersect the sender’s permissions with the receiver’s own policy.

flowchart TD
  A[Sending session tools] --> B[Capture exact permissions]
  B --> C[Trusted Gateway handoff]
  C --> D[Check live sender authority]
  D --> E[Receiver policy and runtime]
  E --> F[Local or CLI tools]
  E --> G[Worker tool grant]
  F --> H[Allowed tool effects]
  G --> H
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the revised capture, receiving admission, and worker launch need observable allowed and sender-denied effects, plus rejection after source completion, cancellation, or replacement. Current tests stop at mocked projection or dispatch; the predecessor's valid filesystem/WebSocket traces exercise replaced machinery. Provide redacted terminal traces or logs, removing credentials, private endpoints, IP addresses, and personal data; update the PR body for re-review, or ask a maintainer for @clawsweeper re-review if needed.
  • [P1] Enforce the exact ceiling before launching a receiving worker (P1) - This newly passes toolExecutionAllow into embedded execution, but a worker placement bypasses the local catalog gate. resolveWorkerToolAuthority reads only turn.toolsAllow; its existing test explicitly expands ["write"] into ["write", "apply_patch"]. The launch descriptor then makes both executable. A sender excluding apply_patch therefore regains it at a permissive worker receiver. Intersect the final worker projection with the exact ceiling before registering or serializing authority.
  • [P2] Stop advertising operations rejected by the capped send tool (P2) - Normal tool assembly now supplies a cap even without restrictive configuration, so this guard deterministically rejects notify, steer, resume, watch:true, and zero-timeout sends. However, the returned schema and describeSessionsSendTool() still instruct the model to use those operations, including paused-child resume, and the public session-tool docs promise nonblocking sends. Project the supported schema and description for capped tools and update the documented contract so agents are not directed into guaranteed failures.
  • Resolve security concern: Worker receivers widen the sender's exact tool authority - Policy expansion adds apply_patch to a write-only transferred cap, and worker execution consumes that expanded grant without the local embedded execution gate.
  • Resolve merge risk (P1) - Existing fire-and-forget sends, watches, and delayed announcements stop working under the default cap; fresh and upgraded workflow evidence is still needed for this intentional change.
  • Resolve merge risk (P1) - The revised authority chain has no final-effect evidence showing that sender completion, cancellation, or replacement prevents subsequent receiver I/O.
  • Complete next step (P2) - Repair worker ceiling enforcement, align the capped send contract, and attach final-effect authority and upgrade evidence for the revised implementation.

Findings

  • [P1] [P1] Enforce the exact ceiling before launching a receiving worker — src/agents/command/attempt-execution.ts:1403-1404
  • [P2] [P2] Stop advertising operations rejected by the capped send tool — src/agents/tools/sessions-send-tool.ts:644-647
  • [high] Worker receivers widen the sender's exact tool authority — src/gateway/worker-environments/worker-tool-authority.ts:93
Agent review details

Security

Needs attention: Worker authority projection leaves the new exact delegation ceiling unenforced; no unrelated supply-chain changes were found.

PR surface

Source +116, Tests +62. Total +178 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 19 125 9 +116
Tests 2 63 1 +62
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 188 10 +178

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Complete enforcement and the supported contract (recommended)
    Intersect worker grants with the exact ceiling, align advertised send operations, and demonstrate permitted, denied, revoked, and upgraded behavior before landing.

Technical review

Best possible solution:

Use the existing worker authority owner to enforce the exact ceiling, publish an accurate capped-send contract, and establish fresh and upgrade behavior through final-effect proof.

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

Yes, from source: send from a session allowing write but excluding apply_patch to a worker receiver whose policy permits both; worker projection expands the transferred list. No runtime reproduction was executed in this read-only review.

Is this the best way to solve the issue?

No, not yet: the local and CLI repairs use appropriate existing owners, but the worker grant must also consume the exact ceiling and the model-facing contract must reflect the restricted operations.

Full review comments:

  • [P1] [P1] Enforce the exact ceiling before launching a receiving worker — src/agents/command/attempt-execution.ts:1403-1404
    This newly passes toolExecutionAllow into embedded execution, but a worker placement bypasses the local catalog gate. resolveWorkerToolAuthority reads only turn.toolsAllow; its existing test explicitly expands ["write"] into ["write", "apply_patch"]. The launch descriptor then makes both executable. A sender excluding apply_patch therefore regains it at a permissive worker receiver. Intersect the final worker projection with the exact ceiling before registering or serializing authority.
    Confidence: 0.98
  • [P2] [P2] Stop advertising operations rejected by the capped send tool — src/agents/tools/sessions-send-tool.ts:644-647
    Normal tool assembly now supplies a cap even without restrictive configuration, so this guard deterministically rejects notify, steer, resume, watch:true, and zero-timeout sends. However, the returned schema and describeSessionsSendTool() still instruct the model to use those operations, including paused-child resume, and the public session-tool docs promise nonblocking sends. Project the supported schema and description for capped tools and update the documented contract so agents are not directed into guaranteed failures.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 08c998f90b26.

Labels

Label justifications:

  • P1: This addresses cross-session tool-authority escalation in an established agent workflow.
  • merge-risk: 🚨 security-boundary: Receiving workers can expand a transferred exact write cap into apply_patch authority.
  • merge-risk: 🚨 compatibility: The default cap rejects shipped nonblocking sends and removes their delayed announcement behavior.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the revised capture, receiving admission, and worker launch need observable allowed and sender-denied effects, plus rejection after source completion, cancellation, or replacement. Current tests stop at mocked projection or dispatch; the predecessor's valid filesystem/WebSocket traces exercise replaced machinery. Provide redacted terminal traces or logs, removing credentials, private endpoints, IP addresses, and personal data; update the PR body for re-review, or ask a maintainer for @clawsweeper re-review if needed.

Evidence

Security concerns:

  • [high] Worker receivers widen the sender's exact tool authority — src/gateway/worker-environments/worker-tool-authority.ts:93
    Policy expansion adds apply_patch to a write-only transferred cap, and worker execution consumes that expanded grant without the local embedded execution gate.
    Confidence: 0.98

What I checked:

  • Pinned introduction and current PR state: The reviewed checkout is the original head 448c7d521ec9a1cb283b0a318d6486f001740b4b, with recorded parent 9a05f9eb338c84b5395c18bdd2afb62c821bd3c6. GitHub confirms the PR remains open, unmerged, MEMBER-authored, and stacked on sec/fail-closed-delegated-tool-cap-v2. (448c7d521ec9)
  • Current main still lacks session-send cap admission: Current main selects plugin-subagent or restored-cron allowlists at receiving dispatch; it does not consume sessionsSendToolsAllow or bind the sending session's assertion here. No merged replacement is established by the related-item context. (src/gateway/agent-turn/agent-run-execution-phase.ts:432, 08c998f90b26)
  • Prior findings checked against revised source: The revised branch intersects embedded outgoing session/spawn captures with toolExecutionAllow, selects exact CLI grant projection, and rejects capped ACP dispatch before backend execution. The earlier reviewed object 5fb43680dc430869c6c277e18a76e3240c378180 was unavailable locally, so unchanged-code continuity could not be established for newly identified concerns. (src/agents/embedded-agent-runner/run/attempt-bundle-tools.ts:210, 448c7d521ec9)
  • Worker receiver does not consume the exact ceiling: The introduced command handoff supplies toolExecutionAllow, but worker placement bypasses local embedded catalog gating. resolveWorkerToolAuthority uses only toolsAllow and returns the policy-expanded projection without intersecting toolExecutionAllow. (src/gateway/worker-environments/worker-tool-authority.ts:93, 448c7d521ec9)
  • Worker expansion reaches executable tools: The existing worker-authority test explicitly expects toolsAllow=[write] to yield write and apply_patch. worker-turn-execution.ts registers and serializes that authority; embedded-agent.runtime.ts selects executable local tools from the resulting names. A receiver that permits apply_patch can therefore regain it despite its absence from the sender's exact cap. (src/gateway/worker-environments/worker-tool-authority.test.ts:121, 448c7d521ec9)
  • Advertised modes contradict the new default restriction: Normal coding-tool assembly always supplies the cap array. The new guard rejects notify, steer, resume, watch=true, and zero-timeout calls, while the unchanged schema and describeSessionsSendTool still advertise those operations. Current session-tool documentation also promises nonblocking sends, task resume, watches, and delayed announcements. (src/agents/tools/sessions-send-tool.ts:644, 448c7d521ec9)

Likely related people:

  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Apply the exact ceiling at worker grant creation and cover a write-allowed, apply_patch-denied sender.
  • Align capped tool schemas, descriptions, and documentation with the supported send modes and demonstrate upgrade behavior.
  • Show allowed and forbidden final effects and prove source revocation prevents receiver I/O through the revised production path.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-17T07:19:58.335Z sha 5aa9c71 :: needs real behavior proof before merge. :: [P1] [P1] Capture the session-send cap after the MCP grant filter | [P1] [P1] Enforce the transferred names as an exact ceiling | [P1] [P1] Retain source authority through receiving-tool execution
  • reviewed 2026-09-17T07:41:48.852Z sha 5fb43680dc430869c6c277e18a76e3240c378180 :: needs real behavior proof before merge. :: [P1] [P1] Intersect the outgoing cap with the current execution ceiling | [P1] [P1] Preserve exactness during CLI catalog materialization | [P1] [P1] Reject capped ACP handoffs before backend execution

@vincentkoc
vincentkoc force-pushed the sec/fail-closed-delegated-tool-cap-v2 branch from 330a2ba to 971b785 Compare September 17, 2026 07:24
@vincentkoc
vincentkoc force-pushed the sec/cap-delegated-session-tools branch from 5aa9c71 to 806b162 Compare September 17, 2026 07:24
@vincentkoc
vincentkoc marked this pull request as ready for review September 17, 2026 07:24
@vincentkoc
vincentkoc force-pushed the sec/cap-delegated-session-tools branch from 806b162 to 1e25a3d Compare September 17, 2026 07:29
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc force-pushed the sec/cap-delegated-session-tools branch from 5fb4368 to 2344ee6 Compare September 17, 2026 07:44
@vincentkoc

Copy link
Copy Markdown
Member Author

Addressed all exact-head findings narrowly: outgoing session/spawn caps are intersected with the run execution ceiling after refresh, exact CLI handoffs use exact grant projection instead of policy aliases, and capped ACP handoffs fail before backend execution. @clawsweeper re-review

@vincentkoc
vincentkoc force-pushed the sec/cap-delegated-session-tools branch 2 times, most recently from 60c87d8 to 448c7d5 Compare September 17, 2026 07:57
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc force-pushed the sec/cap-delegated-session-tools branch from 448c7d5 to d4960e1 Compare September 17, 2026 08:13
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc requested a review from a team as a code owner September 17, 2026 08:17
@vincentkoc

Copy link
Copy Markdown
Member Author

Closing rather than landing: closure-bound sender authority cannot preserve the existing post-return notify, steer, resume, watch, and zero-timeout sessions_send contract. Shipping this cap by default would break established behavior. #150702 retains the safe restart-recovery slice; #144269 retains the original context and contributor credit.

@vincentkoc vincentkoc closed this Sep 17, 2026
@RomneyDa
RomneyDa deleted the sec/cap-delegated-session-tools branch October 22, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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