Skip to content

fix(security): sanitize JSON-escaped forged content boundaries - #118698

Merged
steipete merged 1 commit into
mainfrom
codex/qa0803-external-content-marker-escaping
Aug 3, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa0803-external-content-marker-escaping

Conversation

@steipete

@steipete steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Neutralize forged external-content begin/end markers even after hostile content has been JSON-encoded.
  • Preserve the existing linear-time sanitizer and random authoritative trust-boundary framing.

Root cause and shared security ownership

Browser tab titles, snapshots, console output, web_fetch, search, email, and webhook payloads are JSON-stringified before reaching the canonical wrapExternalContent sanitizer. JSON escapes the quotes in an attacker-supplied marker ID, but the existing start/end matcher only recognized unescaped quotes. Actual production Browser wrappers therefore reported untrusted:true while leaving both forged boundaries intact; this has shipped since early stable releases.

The two existing canonical regular expressions now accept zero or any number of JSON-escape backslashes before the ID quote. No Browser-local workaround, new wrapper, altered schema, or repeated parsing is introduced; the negated ID character class remains linear-time and supports long IDs.

Actual production security proof

Before repair, the actual unmocked Browser tabs/console/snapshot helper returned {"forgedIdRetained":true,"startSanitized":false,"endSanitized":false,"boundaryNames":4,"untrusted":true}.

After repair, each actual production path returns {"forgedIdRetained":false,"startSanitized":true,"endSanitized":true,"boundaryNames":2,"untrusted":true}; real web_fetch, search, email, webhook, and channel metadata owners match.

  • Six genuine RED cases became GREEN; full existing security owner suite 73/73 passing.
  • Covers arbitrary JSON nesting, 4,096-character IDs, mixed case/fullwidth/zero-width variants, benign JSON, and linear-time hostile tails.
  • Type-aware/type-check lint, formatting, and diff checks clean.
  • Fresh independent structured Sol/high security review: no findings, confidence 0.95.
  • Production delta zero lines (existing regex only); focused tests +38.

@steipete
steipete requested a review from a team as a code owner August 3, 2026 14:06
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 3, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 3, 2026, 10:16 AM ET / 14:16 UTC.

ClawSweeper review

What this changes

The PR expands the shared external-content marker matcher to remove forged begin/end boundaries after JSON serialization and adds regression coverage for serialized Browser, search, and fetch payloads.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for the required maintainer security-boundary decision. Current main still fails to sanitize forged markers whose attribute quotes were JSON-escaped, and the patch repairs that shared owner path without adding a parallel Browser-only workaround.

Priority: P0
Reviewed head: b3cff4426b8e49d7433dde24cfa3564ebad3028e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused shared-owner security repair with direct regression coverage and supplied runtime evidence; remaining work is protected-label review and current-head validation.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides before/after unmocked Browser-helper output showing forged IDs and boundaries removed, and the supplied check context records a successful Real behavior proof job.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides before/after unmocked Browser-helper output showing forged IDs and boundaries removed, and the supplied check context records a successful Real behavior proof job.
Evidence reviewed 6 items Current main still misses escaped attribute quotes: The canonical matcher accepts only id="..."; JSON serialization inserts backslashes before each quote, so a serialized forged marker does not match before wrapping.
Browser path serializes before sanitizing: The Browser snapshot helper JSON-stringifies page-controlled payloads and then sends the resulting text to wrapExternalContent, establishing the reported escaped-marker path in an owned caller.
Patch stays at the canonical owner boundary: The supplied PR patch changes only the two shared marker regular expressions to accept zero or more JSON-escape backslashes before quotes and adds six focused serialized-input cases.
Findings None None.
Security None None.

How this fits together

Browser, web, email, webhook, and channel-metadata text enter one external-content security wrapper before becoming model-visible prompt context. That wrapper sanitizes spoofed boundary markers and emits a fresh random boundary around the remaining untrusted payload.

flowchart LR
  A[Browser and external sources] --> B[Serialized page or tool content]
  B --> C[External-content sanitizer]
  C --> D[Fresh random trust boundary]
  D --> E[Model-visible prompt context]
Loading

Decision needed

Question Recommendation
Should OpenClaw accept this shared-boundary repair, which intentionally strips marker-shaped content with any JSON-serialization depth across every external-content source? Accept the shared repair: Approve the canonical matcher change after current-head checks pass, preserving protection for nested JSON-serialized external content.

Why: The code path is security-sensitive and carries the protected maintainer label; accepting the cross-source false-positive tradeoff requires explicit maintainer intent even though the implementation is narrowly scoped.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main (cad499d7 base versus current c547f165), so mergeability and required checks should be refreshed against the current merge result before landing; this is not a patch defect.
Agent review details

Security

None.

PR surface

Source 0, Tests +38. Total +38 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 4 0
Tests 1 38 0 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 42 4 +38

Review metrics

Metric Value Why it matters
Production versus test delta production +4/-4; tests +38/-0 The behavioral repair is net-neutral in production code while adding focused coverage for the newly recognized serialized-input variants.

Stored data model

Persistent data-model change detected: serialized state: src/security/external-content.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the single shared sanitizer repair, refresh it against current main, and land only after a maintainer accepts the deliberately broader serialized-marker sanitation behavior and the exact merge head is green.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the single shared sanitizer repair, refresh it against current main, and land only after a maintainer accepts the deliberately broader serialized-marker sanitation behavior and the exact merge head is green.

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

Yes, at source level: Browser snapshot code JSON-stringifies page-controlled payloads before calling the canonical wrapper, while current main matches only unescaped id="..." marker attributes. This read-only review did not execute the failing path, but the reproduction mechanism is direct and covered by the proposed regression cases.

Is this the best way to solve the issue?

Yes. Updating replaceMarkers is the narrowest maintainable solution because every affected caller reaches that shared sanitizer; a Browser-local workaround would leave web and other serialized external-content owners inconsistent.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P0: The PR repairs a bypass of the shared trust boundary that protects model-visible external content from forged framing.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after unmocked Browser-helper output showing forged IDs and boundaries removed, and the supplied check context records a successful Real behavior proof job.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides before/after unmocked Browser-helper output showing forged IDs and boundaries removed, and the supplied check context records a successful Real behavior proof job.

Label justifications:

  • P0: The PR repairs a bypass of the shared trust boundary that protects model-visible external content from forged framing.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides before/after unmocked Browser-helper output showing forged IDs and boundaries removed, and the supplied check context records a successful Real behavior proof job.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after unmocked Browser-helper output showing forged IDs and boundaries removed, and the supplied check context records a successful Real behavior proof job.

Evidence

What I checked:

  • Current main still misses escaped attribute quotes: The canonical matcher accepts only id="..."; JSON serialization inserts backslashes before each quote, so a serialized forged marker does not match before wrapping. (src/security/external-content.ts:250, c547f16506e6)
  • Browser path serializes before sanitizing: The Browser snapshot helper JSON-stringifies page-controlled payloads and then sends the resulting text to wrapExternalContent, establishing the reported escaped-marker path in an owned caller. (extensions/browser/src/browser-tool.snapshot.ts:47, c547f16506e6)
  • Patch stays at the canonical owner boundary: The supplied PR patch changes only the two shared marker regular expressions to accept zero or more JSON-escape backslashes before quotes and adds six focused serialized-input cases. (src/security/external-content.ts:250, b3cff4426b8e)
  • Recent security-path provenance: Blame attributes the present marker replacement implementation to a recent Peter Steinberger commit; earlier history also includes a forged-marker sanitization hardening change in the same file. (src/security/external-content.ts:235, 96b4258734ee)
  • The repair is not already on main or released: The PR head is not an ancestor of current main, and no local release tag contains the PR commit; this remains an active fix rather than an implemented-on-main cleanup. (src/security/external-content.ts:250, b3cff4426b8e)
  • After-fix behavior proof supplied: The PR body records before/after output from the unmocked Browser helper, with forged IDs and both boundary names removed after the change; supplied check context also reports the Real behavior proof job as successful. (src/security/external-content.test.ts:226, b3cff4426b8e)

Likely related people:

  • steipete: Recent blame assigns the current marker sanitizer to Peter Steinberger, and his earlier commit history includes the preceding forged-marker hardening work. (role: recent security-path contributor; confidence: high; commits: 96b4258734ee, dea1fe1f1125; files: src/security/external-content.ts, src/security/external-content.test.ts)
  • Vincent Koc: Feature history shows Vincent Koc authored the external-content sanitization and later session-memory sanitation work in this same module. (role: external-content feature contributor; confidence: medium; commits: a97b9014a237, 8b78ae2855c2; files: src/security/external-content.ts)

Rank-up moves

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

  • Refresh required checks on the current merge result before landing.

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.

@steipete
steipete merged commit 67e1b27 into main Aug 3, 2026
201 of 208 checks passed
@steipete
steipete deleted the codex/qa0803-external-content-marker-escaping branch August 3, 2026 14:36
@steipete

steipete commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 3, 2026
* origin/main:
  fix(onboard): keep referenced provider secrets out of plaintext (#118702)
  docs: show canonical agent roster configuration (#118722)
  fix(channels): generate catalog from package manifests (#118097)
  fix(zalouser): distinguish probe timeout from auth failure (#111336)
  improve(ui): cut E2E shard runtime by reusing the bundle (#118697)
  fix(cli): publish completion caches atomically (#118715)
  fix(whatsapp): honor disabled self-chat without widening group access (#118711)
  fix(voice-call): terminate carrier calls after realtime startup failures (#118699)
  fix(slack): isolate GovSlack media trust and delivery (#118695)
  fix(browser): wrap page-controlled action results (#118691)
  fix(security): sanitize JSON-escaped forged content boundaries (#118698)
  test(qa): prove real yielded-child completion and channel delivery (#118707)
  fix(doctor): honor explicit plugin-only migration authority (#118700)
  fix(security): detect child_process calls through aliases and computed members (#116304)
  test(gateway): avoid async facade mock race (#118708)
  fix(gateway): preserve final speech during transcription shutdown (#118693)
  fix(gateway): resume durable outbound delivery retries (#118694)
  fix(plugins): reject external public-artifact hardlinks (#118689)
vincentkoc added a commit that referenced this pull request Aug 3, 2026
* origin/main: (78 commits)
  fix(parallels): recover Windows poll transport failures (#118479)
  fix(channels): deny unauthorized Discord and Telegram binding access (#118704)
  fix(test): bound shared git inventory lookup (#111171)
  fix(onboard): keep referenced provider secrets out of plaintext (#118702)
  docs: show canonical agent roster configuration (#118722)
  fix(channels): generate catalog from package manifests (#118097)
  fix(zalouser): distinguish probe timeout from auth failure (#111336)
  improve(ui): cut E2E shard runtime by reusing the bundle (#118697)
  fix(cli): publish completion caches atomically (#118715)
  fix(whatsapp): honor disabled self-chat without widening group access (#118711)
  fix(voice-call): terminate carrier calls after realtime startup failures (#118699)
  fix(slack): isolate GovSlack media trust and delivery (#118695)
  fix(browser): wrap page-controlled action results (#118691)
  fix(security): sanitize JSON-escaped forged content boundaries (#118698)
  test(qa): prove real yielded-child completion and channel delivery (#118707)
  fix(doctor): honor explicit plugin-only migration authority (#118700)
  fix(security): detect child_process calls through aliases and computed members (#116304)
  test(gateway): avoid async facade mock race (#118708)
  fix(gateway): preserve final speech during transcription shutdown (#118693)
  fix(gateway): resume durable outbound delivery retries (#118694)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 4, 2026
* origin/main:
  fix(onboard): keep referenced provider secrets out of plaintext (openclaw#118702)
  docs: show canonical agent roster configuration (openclaw#118722)
  fix(channels): generate catalog from package manifests (openclaw#118097)
  fix(zalouser): distinguish probe timeout from auth failure (openclaw#111336)
  improve(ui): cut E2E shard runtime by reusing the bundle (openclaw#118697)
  fix(cli): publish completion caches atomically (openclaw#118715)
  fix(whatsapp): honor disabled self-chat without widening group access (openclaw#118711)
  fix(voice-call): terminate carrier calls after realtime startup failures (openclaw#118699)
  fix(slack): isolate GovSlack media trust and delivery (openclaw#118695)
  fix(browser): wrap page-controlled action results (openclaw#118691)
  fix(security): sanitize JSON-escaped forged content boundaries (openclaw#118698)
  test(qa): prove real yielded-child completion and channel delivery (openclaw#118707)
  fix(doctor): honor explicit plugin-only migration authority (openclaw#118700)
  fix(security): detect child_process calls through aliases and computed members (openclaw#116304)
  test(gateway): avoid async facade mock race (openclaw#118708)
  fix(gateway): preserve final speech during transcription shutdown (openclaw#118693)
  fix(gateway): resume durable outbound delivery retries (openclaw#118694)
  fix(plugins): reject external public-artifact hardlinks (openclaw#118689)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant