Skip to content

fix(approvals): sanitize plugin titles and exec paths at the creation boundary - #123742

Merged
steipete merged 5 commits into
mainfrom
codex/autoqa-approval-sanitize
Aug 14, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/autoqa-approval-sanitize

Conversation

@steipete

@steipete steipete commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin approval title/description/detail were stored raw and flowed unescaped to every live reviewer surface: channel messages (buildPluginApprovalRequestMessage), iOS lock-screen push (APNs alert body), and the web modal title/<pre> body. Exec approvals' display-only cwd/resolvedPath had the same gap in the UI meta rows and the forwarder's CWD: line. Bidi override and invisible characters — the exact class the exec sanitizer names — can visually spoof what an operator thinks they are approving. The agent (i.e., a prompt-injected model) controls these strings, so this is attacker-reachable.

Why This Change Was Made

The intended pattern already exists on the sibling: exec command text is sanitized once at request creation (sanitizeExecApprovalDisplayTextWithStatus in exec-approval.ts), so the stored record — and every event/surface built from it — is safe. The durable presentation (approval-presentation.ts) sanitizes its own copy, the TUI sanitizes locally, and the CLI was fixed by #123671, but the live event payload is built from the raw stored record and reaches push/channels/web modal unsanitized.

Fix at the creation boundary (the owner): sanitize plugin title/description/detail in plugin.approval.request, and exec's display-only cwd/resolvedPath in exec.approval.request. Sanitization is idempotent (escapes are plain ASCII), so downstream re-sanitizes become harmless defense. One dead-end fixed alongside: escaping expands invisibles to \u{...} so a spoof-heavy title can exceed the protocol cap post-sanitize — that used to surface as a misleading registration throw ("approval cannot be persisted without a valid reviewer presentation"); it is now a proper INVALID_REQUEST at the boundary.

Execution binding is unaffected: exec runs bind effectiveCwd via systemRunBinding (verified node-invoke-system-run-approval-match.ts builds the actual binding from its own cwd), and resolvedPath's only non-display consumers are outside the approval record. Noted inline.

User Impact

Approval prompts on channels, iOS push, and the Control UI can no longer be visually spoofed via bidi/invisible characters in plugin-supplied titles or agent-supplied paths. Oversized-after-sanitize titles fail with a clear request error instead of an internal registration failure.

Evidence

  • 3 new regression tests fail pre-fix, pass post-fix (git stash proof: 3 failed pre-fix): stored+broadcast plugin payload sanitized; post-sanitize cap rejection; exec cwd/resolvedPath escaped.
  • Suites green: plugin-approval.test.ts (37), exec-approval.agent-runtime.test.ts (5), approval-presentation.test.ts, exec-approval-forwarder.test.ts, exec-approval-ios-push.test.ts.
  • pnpm tsgo clean; oxfmt/oxlint clean.
  • Autoreview (Codex, commit mode): clean, overall 0.98.

Production LOC delta: +33 (sanitize-at-boundary + cap re-check + invariant comments); tests +75.

Update (addendum commit)

ClawSweeper's P1 finding was correct: the node-policy approval runtime (src/gateway/node-invoke-plugin-policy.ts) — the sibling creator feeding the identical broadcast/forwarder/push paths — truncated title/description but never sanitized them. The addendum routes it through the same boundary: normalize → sanitize → truncate (normalize-first keeps the whitespace-only-title fail-closed register behavior; sanitize-before-truncate keeps escape expansion inside the caps). New regression test (node-invoke-plugin-policy.test.ts "sanitizes node-policy approval titles at creation like the RPC ingress") proves the stored record carries escaped text through the real manager.create → register → broadcast path; the pre-existing "fails closed before routing an unrenderable persistent policy approval" test still passes, proving the whitespace contract held. Full suite: 25/25.

On the real-behavior-proof gate: the changed path is gateway-internal record construction; the added tests execute the real approval manager, real registration (including durable presentation validation), and the real broadcast payload builder — no mock gateway is interposed on the changed surface. Channel/push delivery consume record.request verbatim (unchanged code), which the tests pin post-sanitize.

Update 2 (metadata + detail-cap addendum)

Both re-review findings verified and fixed at the same boundary:

  • P1 metadata: pluginId/toolName/fallback agentId are interpolated into channel approval text (buildPluginApprovalRequestMessage Tool:/Plugin:/Agent: lines) and were stored raw. Untrusted values now get sanitizeExecApprovalDisplayText; host-minted runtime identity values (approvalOwnerPluginId, trustedAgentRuntime.agentId, session-owner agentId) stay authoritative and unescaped (noted inline).
  • P2 detail cap: stored detail now applies truncatePluginApprovalDetail post-sanitize, matching the durable presentation's copy — a detail passing the protocol's raw 16,384 cap can no longer exceed it in storage via escape expansion.

Regression test extended: hostile metadata escaped in the stored record; oversized-after-sanitize detail capped with the truncation suffix. Suites green: plugin-approval.test.ts (35), node-invoke-plugin-policy.test.ts (25), exec-approval.agent-runtime.test.ts (5). Autoreview on the addendum: clean, 0.99.

Update 3 (node-policy metadata)

Final sibling closed per the re-review: the node-policy creator's toolName and fallback agentId (interpolated into channel approval text) now go through the same display escape via a shared sanitizeOptionalMeta helper; host-minted callerIdentity values stay authoritative. Regression extended to assert escaped metadata in the stored record through the real registration path. node-invoke-plugin-policy.test.ts 25/25 green; autoreview clean 0.99.

Update 4 (exec reviewer metadata)

Remaining exec metadata addressed per the latest review: security/ask are closed enums, so they now go through the canonical normalizeExecSecurity/normalizeExecAsk at creation — arbitrary strings null out instead of reaching reviewer meta rows (stronger than escaping; decision resolution already treated invalid values as null). host gets the display escape (identity for the valid enum values). nodeId/agentId/sessionKey intentionally stay raw — they are matched against the node registry and session routing, so escaping would break real lookups without display gain; noted inline. Regression extended (hostile security/ask null out); 21 exec-approval tests green; autoreview clean 0.99.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 14, 2026 16:27
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added 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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 14, 2026, 4:35 PM ET / 20:35 UTC.

ClawSweeper review

What this changes

The PR sanitizes plugin approval text and selected exec approval display fields when records are created, with regression coverage for escaped text and post-sanitization limits.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

The PR closes several approval-text spoofing paths, but a routing-bound node identifier remains raw and is interpolated directly into forwarded reviewer text. That leaves the central security invariant incomplete.

Priority: P1
Reviewed head: 8c3f157cb668b304df71c4a89ac84d933b4a6a7d

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The boundary-focused repair is useful, but the remaining raw binding display path blocks merge readiness.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: This maintainer-authored PR is reviewed on its Gateway boundary and supplied regression evidence; the external contributor-proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is reviewed on its Gateway boundary and supplied regression evidence; the external contributor-proof gate does not apply.
Evidence reviewed 6 items Current reviewer rendering: Current main interpolates the stored node identifier directly into the forwarded Node: line.
PR-head raw binding: The PR intentionally keeps nodeId raw in the stored request while adding sanitization for other display fields.
Binding contract: The execution guard compares the stored nodeId byte-for-byte with the target node, so sanitizing it in place would break authorization binding.
Findings 1 actionable finding [P1] Project raw node bindings into escaped reviewer text
Security Needs attention Raw node identifier reaches reviewer chat: The node binding is stored unescaped and forwarded directly into the human approval prompt.

How this fits together

Gateway approval requests become pending records, then feed reviewer broadcasts to chat, push, and the Control UI. Node approvals also retain exact binding data so an authorization can only execute on its original node.

flowchart LR
  A[Plugin or exec request] --> B[Gateway approval creation]
  B --> C[Pending approval record]
  C --> D[Node binding check]
  C --> E[Reviewer broadcast]
  E --> F[Chat and push prompt]
  E --> G[Control UI]
Loading

Before merge

  • Project raw node bindings into escaped reviewer text (P1) - nodeId must remain byte-exact for the node-binding comparison, but the forwarder renders the stored value directly as Node:. A bidi/control-containing ID can still spoof the operator despite this patch’s reviewer-surface goal. Add an escaped display projection used by chat and UI renderers, then cover it through registration and forwarding.
  • Resolve security concern: Raw node identifier reaches reviewer chat - The node binding is stored unescaped and forwarded directly into the human approval prompt.
  • Resolve merge risk (P1) - A bidi/control-containing node identifier can still spoof the forwarded reviewer prompt.
  • Resolve merge risk (P1) - The PR is production +73 net lines; the follow-up should centralize reviewer display projection rather than add another scattered sanitizer.
  • Complete next step (P2) - The concrete blocker is security-boundary design on a maintainer-authored protected PR; it needs an owner-reviewed revision.

Findings

  • [P1] Project raw node bindings into escaped reviewer text — src/gateway/server-methods/exec-approval.ts:332-335
  • [medium] Raw node identifier reaches reviewer chat — src/gateway/server-methods/exec-approval.ts:335
Agent review details

Security

Needs attention: A raw node binding still reaches the forwarded approval prompt, leaving reviewer-spoofing protection incomplete.

PR surface

Source +73, Tests +128. Total +201 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 89 16 +73
Tests 3 128 0 +128
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 217 16 +201

Review metrics

Metric Value Why it matters
Production versus test delta production +73 net (+89/-16), tests +128 The security-boundary growth is justified only if the completed design covers every reviewer-visible field without duplicating policy.

Root-cause cluster

Relationship: canonical
Canonical: #123742
Summary: This PR is the active repair for approval reviewer-text spoofing; the earlier terminal-rendering fix overlaps but does not cover the live broadcast path.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Add a safe display projection (recommended)
    Keep raw authorization bindings while routing every reviewer surface through escaped node, agent, and session display values.

Technical review

Best possible solution:

Preserve raw node/session values for authorization, add escaped reviewer-display values, and make chat and Control UI rendering consume those values with an end-to-end hostile-node regression.

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

Yes: create a node approval with bidi or invisible characters in its node identifier and inspect the forwarded Node: line, which current main interpolates without escaping.

Is this the best way to solve the issue?

No: mutating the stored node identifier would break exact authorization binding; a separate escaped display projection is the maintainable repair.

Full review comments:

  • [P1] Project raw node bindings into escaped reviewer text — src/gateway/server-methods/exec-approval.ts:332-335
    nodeId must remain byte-exact for the node-binding comparison, but the forwarder renders the stored value directly as Node:. A bidi/control-containing ID can still spoof the operator despite this patch’s reviewer-surface goal. Add an escaped display projection used by chat and UI renderers, then cover it through registration and forwarding.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A remaining raw node identifier can misrepresent an operator security approval in forwarded chat.
  • merge-risk: 🚨 security-boundary: Approval text directly informs an operator decision to authorize execution.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is reviewed on its Gateway boundary and supplied regression evidence; the external contributor-proof gate does not apply.

Evidence

Security concerns:

  • [medium] Raw node identifier reaches reviewer chat — src/gateway/server-methods/exec-approval.ts:335
    The node binding is stored unescaped and forwarded directly into the human approval prompt.
    Confidence: 0.98

What I checked:

Likely related people:

  • steipete: Authored this PR’s boundary changes and the related merged approval terminal-rendering repair. (role: recent approval-rendering contributor; confidence: high; commits: 7c579abf067f, f63c7a19193c, 8c3f157cb668; files: src/gateway/server-methods/exec-approval.ts, src/infra/exec-approval-forwarder.ts, src/gateway/node-invoke-system-run-approval.ts)

Rank-up moves

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

  • Add a registration-and-forwarding regression for a hostile node identifier and assert escaped reviewer text.

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 (8 earlier review cycles)
  • reviewed 2026-08-14T16:34:00.297Z sha a296e9d :: needs real behavior proof before merge. :: [P1] Sanitize node-policy plugin approvals through the same boundary
  • reviewed 2026-08-14T17:33:25.634Z sha 17d88da :: found issues before merge. :: [P2] Cap sanitized plugin approval detail before storing it
  • reviewed 2026-08-14T17:50:36.141Z sha c277ae1 :: found issues before merge. :: [P2] Cap sanitized plugin approval detail before storing it
  • reviewed 2026-08-14T18:25:14.863Z sha 4e20749e3401cdf47a6dbbc248c7ad1d79e1b398 :: found issues before merge. :: [P2] Cap sanitized plugin approval detail before storing it
  • reviewed 2026-08-14T19:08:27.624Z sha 4aa0cc69f39ad9f047e28dd0a7211b784b918fc8 :: found issues before merge. :: [P1] Sanitize remaining plugin display metadata | [P2] Cap sanitized plugin detail before storing it
  • reviewed 2026-08-14T19:55:54.124Z sha 698cb37 :: found issues before merge. :: [P1] Sanitize node-policy display metadata
  • reviewed 2026-08-14T20:13:30.871Z sha 61b84e9 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T20:19:40.970Z sha 61b84e9 :: found issues before merge. :: [P1] Sanitize remaining exec reviewer metadata

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Aug 14, 2026
… boundary

Plugin approval title/description/detail were stored raw and flowed
unescaped into channel messages, iOS lock-screen push, and the web modal —
bidi/invisible characters could spoof what the operator approves. Exec
approvals already sanitize command text at creation; mirror that for the
plugin request and for exec's display-only cwd/resolvedPath fields.
Re-check the protocol size caps after escaping so a spoof-heavy title fails
as INVALID_REQUEST instead of a misleading registration throw.
…boundary

The node-policy approval runtime truncated title/description but never
sanitized them, so the identical broadcast/forwarder/push paths stayed
spoofable through this sibling creator (ClawSweeper P1 finding). Normalize
first so a whitespace-only title still fails closed at register.
ClawSweeper follow-ups: pluginId/toolName/fallback agentId are interpolated
into channel approval text and were stored raw; the stored detail skipped
the 16,384 cap the durable presentation applies, so escape expansion could
exceed it. Sanitize the metadata at the same boundary (host-minted runtime
identity stays authoritative) and cap detail at storage.
@steipete
steipete force-pushed the codex/autoqa-approval-sanitize branch from 4aa0cc6 to 698cb37 Compare August 14, 2026 19:45
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
toolName and fallback agentId from node-policy code are interpolated into
channel approval text; escape them like the RPC ingress. Host-minted
runtime identity values stay authoritative.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 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.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
security/ask are closed enums — arbitrary strings now null out via the
canonical normalizers instead of reaching reviewer meta rows; host gets the
display escape (identity for valid values). nodeId/agentId/sessionKey stay
raw by design: they are matched against the node registry and session
routing, noted inline.
@steipete
steipete merged commit a96d135 into main Aug 14, 2026
187 checks passed
@steipete
steipete deleted the codex/autoqa-approval-sanitize branch August 14, 2026 20:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
… boundary (openclaw#123742)

* fix(approvals): sanitize plugin titles and exec paths at the creation boundary

Plugin approval title/description/detail were stored raw and flowed
unescaped into channel messages, iOS lock-screen push, and the web modal —
bidi/invisible characters could spoof what the operator approves. Exec
approvals already sanitize command text at creation; mirror that for the
plugin request and for exec's display-only cwd/resolvedPath fields.
Re-check the protocol size caps after escaping so a spoof-heavy title fails
as INVALID_REQUEST instead of a misleading registration throw.

* fix(gateway): sanitize node-policy plugin approvals through the same boundary

The node-policy approval runtime truncated title/description but never
sanitized them, so the identical broadcast/forwarder/push paths stayed
spoofable through this sibling creator (ClawSweeper P1 finding). Normalize
first so a whitespace-only title still fails closed at register.

* fix(approvals): sanitize plugin metadata and cap stored detail

ClawSweeper follow-ups: pluginId/toolName/fallback agentId are interpolated
into channel approval text and were stored raw; the stored detail skipped
the 16,384 cap the durable presentation applies, so escape expansion could
exceed it. Sanitize the metadata at the same boundary (host-minted runtime
identity stays authoritative) and cap detail at storage.

* fix(gateway): sanitize node-policy approval metadata too

toolName and fallback agentId from node-policy code are interpolated into
channel approval text; escape them like the RPC ingress. Host-minted
runtime identity values stay authoritative.

* fix(approvals): normalize exec policy enums and escape host at creation

security/ask are closed enums — arbitrary strings now null out via the
canonical normalizers instead of reaching reviewer meta rows; host gets the
display escape (identity for valid values). nodeId/agentId/sessionKey stay
raw by design: they are matched against the node registry and session
routing, noted inline.
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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant