Skip to content

fix(policy): sanitize human CLI reports - #186453

Merged
obviyus merged 3 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-policy-cli-terminal-reports-20261027
Oct 28, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-policy-cli-terminal-reports-20261027

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: Policy CLI reports and errors can emit terminal controls or bidi overrides embedded in policy filenames, finding text or agent IDs, allowing data to alter a human-readable terminal report.

User Impact

Human-readable policy check, policy compare and policy watch output sanitizes untrusted data while preserving report layout, ordinary Unicode and application-owned colors. JSON keeps the original values, policy evaluation and exit codes are unchanged, and policy files are never rewritten by this fix.

Why This Change Was Made

Keep Leon-SK668's contributor commit and repair it to use the existing shared terminalText owner through the official plugin SDK facade. Tagged templates distinguish report-owned literals from data values before styling. Remove the local writePolicyLine sanitizer rather than introducing a second output policy or sanitizing a global sink.

Current main was integrated because it changed this CLI and provided the shared owner facade. The final diff touches only the CLI, its existing regression and output-mode documentation. Whole-PR production delta +3 net lines, tests 0 net lines. The duplicate mocked compare case is superseded by the real built-CLI byte evidence below; the existing unknown-owner regression now also exercises control and bidi text.

Evidence

Built CLI raw-byte evidence and controls.

Secretless Linux Docker, Node 24.22.1, complete main/candidate builds; explicit task-owned profiles/config/state. The built CLI ran on a real PTY with echo/newline translation disabled, retaining its stdout as binary and analyzing hex/base64. No paid keys or model calls.

  • Main e094e4c8…: clean and weaker-policy comparisons each reproduced twice. Human stdout contained filename-derived BEL (07), NEL (c2 85), bidi override (e2 80 ae) and injected SGR (1b 5b 33 31 6d).
  • Candidate 49753c91…: both cases passed twice with those unsafe data bytes absent; ordinary café and emoji text remained. Clean/finding exits remained 0/1 and policy files remained unchanged.
  • All four corresponding JSON stdout captures were byte-identical across main/candidate, retaining the original decoded paths.
  • The ordinary ASCII report line was byte-identical. CLI help retained 237 intended SGR sequences on each build with an identical ordered-sequence hash. Startup banner taglines vary randomly and are not claimed byte-identical.
  • The extended existing regression fails on main's raw stderr. Final candidate CLI suite: 38 passed. Oxfmt and Oxlint pass with 0 warnings/errors.

The production repair covers report values and error boundaries only. No policy semantics, persistence, permissions, schema, SDK API or machine-output contract changes.

Merge danger: two-way door; reverting restores unsafe human rendering without a migration. Blast radius is human Policy CLI reports/errors. JSON and normal styling have independent controls above.

@clawsweeper

clawsweeper Bot commented Oct 28, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Sanitize untrusted values in human Policy CLI reports and diagnostics while preserving raw JSON values.

Example: Run policy compare with a filename containing café, BEL, a bidi override, and injected red ANSI styling.

  • Before: The filename's control bytes reach the terminal and can alter report presentation.
  • After: Unsafe controls are removed, café remains readable, and JSON preserves the original filename.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused shared-owner repair with shipped-entry-point byte evidence, an extended regression, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Exact candidate 49753c9 is exercised through the built CLI in secretless Linux Docker on Node 24.22.1 using real PTY clean/finding comparisons with malicious filenames; supplied byte output shows unsafe controls removed while JSON, exits, files, printable Unicode, and intended styling remain intact.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Policy filenames and diagnostic values can inject terminal controls or misleading bidi formatting into human reports.
Reason: A narrow shared-owner repair protects readable reports without adding configuration or changing policy semantics, and collaborator repair and proof confirm the direction.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current terminal-output defect using the existing shared encoder; no actionable introduced bugs were found.

Priority: P2
Reviewed head: 49753c91d71afdd98d16b5665561ab73d606f16c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Policy plugin evaluates workspace policy and compares policy files, then renders findings and errors as terminal text or machine-readable JSON.

flowchart TD
  A[Policy files and CLI arguments] --> B[Policy evaluation and comparison]
  B --> C[Reports and command errors]
  C --> D[Human output selection]
  D --> E[Shared terminal value encoder]
  E --> F[Terminal stdout and stderr]
  C --> G[Unchanged JSON serialization]
Loading

Technical review

Best possible solution:

Land the focused cutover to the existing terminal encoder once the normal exact-head checks pass.

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

Current-main source exposes raw values at the reported boundary, and the supplied built-CLI evidence reproduces that behavior on an unchanged baseline; this review executed no target code.

Is this the best way to solve the issue?

The patch is the smallest complete repair: encode data at existing human-rendering boundaries through the shared owner, retain layout literals, and leave JSON serialization untouched.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Human check, compare, and watch rendering changes intended behavior with a stated reason (Policy: add policy file comparison command #86768: Policy reporting supports read-only conformance review; comparison reports explain strictness and preserve established exit codes.)
  • Shared command failure boundary keeps the original intent (a339211: Emit machine-readable failures for JSON or piped stdout while preserving separate human diagnostics and exit 2.)
  • CLI runtime output ownership keeps the original intent (007a8c5: Remove unused injectable runtime plumbing and consolidate command errors without changing evaluation behavior.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Gio Della-Libera: Raw commit 08beb6b adds extensions/policy/src/cli.ts:327 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 08beb6b0e88f; files: extensions/policy/src/cli.ts)
  • Peter Steinberger: Raw commit 007a8c5 adds extensions/policy/src/cli.ts:136 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 007a8c5bfb4e; files: extensions/policy/src/cli.ts)
  • Leon-SK668: Raw commit a339211 adds extensions/policy/src/cli.ts:116 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a339211296bc; files: extensions/policy/src/cli.ts)
  • Ayaan Zaidi: Raw commit 3bcca4f adds src/plugin-sdk/terminal-safe-text.ts:6 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3bcca4f468ea; files: src/plugin-sdk/terminal-safe-text.ts)

PR surface

Source +3, Tests 0, Docs +3. Total +6 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 15 12 +3
Tests 1 3 3 0
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 21 15 +6

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Control-bearing filenames and diagnostic values can manipulate advanced Policy CLI reports, without changing policy evaluation or enforcement.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-28T02:45:07.884Z sha aa46709 :: needs maintainer review before merge. :: none

Reviewed October 28, 2026, 9:39 AM ET / 13:39 UTC (Revision 2).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS and removed size: S labels Oct 28, 2026
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Built CLI raw-byte proof at the shared terminal owner

Baseline: current-main e094e4c8ceb6bfe1579d443fb299ddba0b5f9915
Candidate: 49753c91d71afdd98d16b5665561ab73d606f16c

Both complete builds succeeded in secretless Linux Docker on Node 24.22.1. The built dist/entry.js CLI ran with explicit task-owned profiles/config/state and checked binary-resolved config/database paths. No model calls or paid keys were used.

Human reports were captured from a real PTY using script, with echo and output newline translation disabled (stty -echo -onlcr). Raw stdout bytes were retained as binary files and analyzed as hex/base64, rather than trusting terminal rendering. CLI stderr was captured separately. The filename contained ordinary café/emoji plus BEL, C1 NEL, U+202E bidi override and an injected ANSI SGR sequence.

The built CLI ran both conformant and weaker-policy comparisons, twice per case on main and twice per case on candidate:

case / repeat       main: unsafe bytes / injected SGR   candidate: unsafe bytes / injected SGR
clean / 1           present / present                   absent / absent
clean / 2           present / present                   absent / absent
finding / 1         present / present                   absent / absent
finding / 2         present / present                   absent / absent

trigger byte sequences in main's human stdout:
BEL       07
C1 NEL    c2 85
RLO       e2 80 ae
ANSI SGR  1b 5b 33 31 6d

candidate human reports retain: caféFORGED🦀.jsonc
clean exit: 0 on both builds
finding exit: 1 on both builds
policy files unchanged by every invocation: true

Independent controls:

  • All four corresponding --json stdout captures are byte-identical between main and candidate. Decoded policy paths preserve the complete original filename, including control/bidi characters. No machine-value sanitization was introduced.
  • The ordinary ASCII compare report line is byte-identical. Full startup banners choose random taglines, so those unrelated prose differences are not presented as a whole-stream equality result.
  • Built CLI --help retains 237 application-owned ANSI SGR sequences on each build, with exactly the same ordered-sequence SHA-256: 56fa935c249b35d0f4643b5e92a1d86780e110a126412146fbcfebafb0165772. Intended colors were not stripped globally.

Owner repair and regression

The contributor's commits are preserved. Current main was merged because it changed this CLI and supplied the shared terminalText facade. Human data now flows through tagged terminalText templates at the existing report/error boundaries. The local writePolicyLine sink sanitizer is removed; JSON branches remain untouched. No new sanitizer, SDK surface or global output filter was added.

The existing unknown-owner regression now includes BEL, C1, bidi and newline characters. It fails main with the raw controls still in stderr, then passes on candidate. The full candidate CLI file reports 38 passed; targeted Oxfmt and Oxlint pass with 0 warnings/errors. The mocked compare duplicate was replaced by the stronger shipped-CLI byte proof above, keeping whole-PR test-line delta 0. Production delta is +3 net lines; documentation records human versus JSON output semantics.

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus
obviyus merged commit e2184d8 into openclaw:main Oct 28, 2026
114 of 116 checks passed
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Landed in e2184d8. Thanks @Leon-SK668. Policy CLI reports now escape untrusted values through the shared owner.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
fix(policy): escape untrusted values in policy CLI reports

The policy CLI's human-readable reports printed filename-derived values and error text raw, so a crafted name could inject BEL, C1, bidi or ANSI control sequences into the terminal. These reports now go through the shared terminalText owner, as the other CLI reports do since openclaw#186502, and the local writePolicyLine sanitizer is removed. JSON output is unchanged.

Evidence: built CLI on Node 24.22.1 with real PTY captures. On main, both the clean and the finding report emitted the injected BEL, C1 NEL, bidi override and ANSI bytes (twice each); with this change they were removed in all four captures and ordinary Unicode was kept. JSON stdout was byte-identical, help kept its 237 intended color sequences, exit codes stayed 0 and 1, and policy files were unchanged. Details: openclaw#186453 (comment).

Thanks @Leon-SK668.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: policy P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

2 participants