Skip to content

fix(cli): escape terminal controls in plugins enable/disable reports - #185895

Closed
huwei-xydt wants to merge 2 commits into
openclaw:mainfrom
huwei-xydt:fix/plugins-enable-terminal-controls
Closed

huwei-xydt wants to merge 2 commits into
openclaw:mainfrom
huwei-xydt:fix/plugins-enable-terminal-controls

Conversation

@huwei-xydt

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes terminal control sequences and forged output rows when openclaw plugins enable / openclaw plugins disable print plugin ids and lifecycle warnings on the Gateway and local-policy paths.

User Impact

Human CLI output stays readable when a config-derived plugin id or lifecycle warning contains ESC/BEL/CSI or newline bytes. Success lines, blocked/missing errors, and warnings no longer let untrusted text control the terminal. JSON/config storage paths are unchanged.

Why This Change Was Made

Same sanitizeTerminalText policy as the merged secrets store human-output fix (#184141) and the open secrets audit/configure PR (#185719). Enable/disable reports interpolate gateway/local mutation results (result.plugin.id, result.pluginId, warnings, deny reason) into human lines without sanitizing them.

Evidence

  • Production: human report lines in the enable/disable policy path now pass through sanitizeTerminalText from packages/terminal-core/src/safe-text.ts. The policy path lives in new sibling src/cli/plugins-cli.enable.ts (extracted from plugins-cli.runtime.ts so the grandfathered runtime module does not grow past the line-cap ratchet). Callers: src/cli/plugins-cli.ts and src/plugins/management-service.policy-imports.test.ts.
  • Tests: two command-boundary regressions in src/cli/plugins-cli.policy.test.ts plant CSI+newline ids and BEL in gateway warnings / denylist reasons on online enable and local enable+blocked reports.
  • Red on fix-without-sanitize: temporarily stripped sanitizeTerminalText from plugins-cli.enable.ts; both new tests failed with raw ESC in human output (Enabled plugin "alpha\u001b[31m\nforged-row"). Sanitizer restored afterward.
  • Green on fix: -t "escapes terminal controls" → 2 passed | 14 skipped. Full file → 16/16 passed.
  • Related consumers green: plugins-install-warning-output.test.ts 3/3; plugins-cli.lazy.test.ts 3/3; management-service.policy-imports.test.ts offline policy path passed.
  • check:line-cap-ratchet --staged --base HEAD → OK (runtime extracted, no cap growth). oxfmt/oxlint on touched files clean.

Notes

  • Title pattern: fix(cli): escape terminal controls in plugins enable/disable reports.
  • Unclaimed free slot from the residual direction-A sweep; does not take already-claimed surfaces (uninstall preview, marketplace empty reports, installed/installation reports, secrets audit/configure, etc.).

Plugin ids and lifecycle warnings printed by openclaw plugins enable/disable
are config-derived and could carry ANSI/C0 controls into the operator terminal.
Sanitize human report lines with sanitizeTerminalText and extract the policy
path into plugins-cli.enable.ts so the grandfathered runtime module does not
grow past its line-cap ratchet.

Co-Authored-By: Claude Code <[email protected]>
@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: M labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR sanitizes plugin IDs, warnings, and denial reasons in human-readable enable/disable reports.

Example: A plugin ID contains alpha, an ANSI color sequence, and a newline followed by forged-row.

  • Before: The report changes terminal formatting and prints forged-row on a separate line.
  • After: The color sequence is removed and the newline appears as literal \n within the report.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation appears correct and preserves existing contracts, but external-PR shipped-behavior proof is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Plugin-management reports can interpret control bytes as terminal commands or forged output rows.
Reason: This restores safe human rendering with an established sanitizer and leaves plugin policy, consent, and persistence unchanged.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: current main still prints these fields without sanitizing them, and this PR provides a focused fix with no introduced correctness defect found.

Priority: P2
Reviewed head: 54542c9420fc27c396df100772075e211655a692

Before merge

  • Add real behavior proof - The changed owner is plugins-cli.enable.ts, but supplied evidence exercises Commander callbacks with mocked Gateway and runtime output; provide terminal screenshots, logs, or live output from actual plugin enable/disable commands covering Gateway warnings and local success/rejection, with IPs, API keys, phone numbers, and non-public endpoints redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted shipped-CLI output showing control-bearing IDs and warnings rendered safely through Gateway and local enable/disable paths.
Agent review details

How this fits together

The plugins CLI sends enablement requests to the running Gateway or the existing local mutation owner, then renders returned IDs, warnings, and outcomes to the terminal.

flowchart TD
CLI[Plugins enable or disable] --> Adapter[CLI policy adapter]
Adapter --> Gateway[Gateway lifecycle client]
Adapter --> Local[Local mutation owner]
Gateway --> Report[Human report fields]
Local --> Report
Report --> Sanitizer[Terminal sanitizer]
Sanitizer --> Terminal[Operator terminal]
Loading

Technical review

Best possible solution:

Retain the existing mutation owners and sanitize untrusted fields only at the human terminal-output boundary.

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

Source traces config-derived IDs and lifecycle warnings into unsanitized terminal reports on current main; the contributor reports red/green regression tests, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch uses the canonical sanitizer at the correct rendering boundary, preserves stored values and mutation semantics, and migrates all references to the extracted command implementation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current-main failure remains: Gateway warnings and success IDs, and local missing, blocked, warning, and success reports interpolate unsanitized values on fetched main. (src/cli/plugins-cli.runtime.ts:72, a4a8f632da0a)
  • Introduced change preserves mutation ownership: The extracted command path retains Gateway routing, capability consent, the local state-owner guard, and lifecycle lease; changes to report fields use the existing sanitizer before terminal styling. (src/cli/plugins-cli.enable.ts:30, 54542c9420fc)
  • Existing sanitizer contract: sanitizeTerminalText strips ANSI sequences and removes control characters while rendering carriage returns, newlines, and tabs as visible escapes. (packages/terminal-core/src/safe-text.ts:11, 54542c9420fc)
  • Original owner intent: The merged shared-enablement refactor explicitly assigns terminal output to adapters while preserving restrictive CLI policy and consent ordering; this PR respects that division. (src/cli/plugins-cli.runtime.ts, 3b90108d098e)
  • Related implementation establishes precedent: The merged secrets-output fix uses the same sanitizer at human-output boundaries; its CLI proof covers secrets store, not plugin enable/disable. (6b72c7911938)
  • Supplied evidence inspected: The full PR body reports red/green command-boundary tests and related passing tests; both discussion comments are bot status updates, with no plugin enable/disable CLI recording, terminal capture, or live output. (src/cli/plugins-cli.policy.test.ts:187, 54542c9420fc)

PR surface

Source +10, Tests +45. Total +55 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 104 94 +10
Tests 2 46 1 +45
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 150 95 +55

Labels

Label changes:

  • add P2: Terminal controls can alter plugin-management reports, but the demonstrated scope is limited to human CLI output.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Terminal controls can alter plugin-management reports, but the demonstrated scope is limited to human CLI output.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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.

Reviewed October 27, 2026, 8:56 AM ET / 12:56 UTC.

Keep the plugins-cli.enable.ts extraction and sanitizing reports; drop
the duplicate enable path that upstream still holds in plugins-cli.runtime.ts.

Co-Authored-By: Claude Code <[email protected]>
obviyus added a commit that referenced this pull request Oct 28, 2026
…amilies (#186502)

fix(cli): route remaining CLI reports through the terminal-text owner

After #185927 added one owner for escaping untrusted values in CLI output, contributors kept opening one PR per command to escape the next report. This moves the remaining human-readable reports in the plugins, secrets, sessions, memory and memory-wiki, workboard, backup, pairing, oc-path, config and setup commands onto `terminalText` / `displayPath`, and extends the owner to neutralize bidirectional control characters. JSON output, persisted identities, raw exports and the CLI's own colors are unchanged, and the trusted styling of `renderTable` is untouched.

This absorbs the per-site fixes from @Leon-SK668 (#184454, #184379, #185374, #186449, #184396, #184788, #184813, #184394), @huwei-xydt (#185895, #185719), @wangmiao0668000666 (#175600, #175181, #175179), @SunnyShu0925 (#184747), @KrasimirKralev (#184597) and @arpe1618 (#150599), whose original commits are kept. Families no PR touched (update, Doctor, install-trust producers and others) are listed under "Not fixed here".

Evidence: 85 built-CLI invocations per ref with crafted control and bidi characters in the reported values, captured as raw stdout bytes. Main printed the raw sequences; this change printed them neutralized, with identical normal colors and unchanged JSON. Details: #186502 (comment).

Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Leon-SK668 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Krasimir Kralev <[email protected]>
Co-authored-by: arpe1618 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @huwei-xydt. This is now fixed at the root in #186502 (3bcca4f), which routes the remaining CLI reports through the shared terminalText owner from terminal-core. Your commit is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new output sites, please pass untrusted values through terminalText (or displayPath for paths) rather than opening a PR per command.

@obviyus obviyus closed this Oct 28, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…amilies (openclaw#186502)

fix(cli): route remaining CLI reports through the terminal-text owner

After openclaw#185927 added one owner for escaping untrusted values in CLI output, contributors kept opening one PR per command to escape the next report. This moves the remaining human-readable reports in the plugins, secrets, sessions, memory and memory-wiki, workboard, backup, pairing, oc-path, config and setup commands onto `terminalText` / `displayPath`, and extends the owner to neutralize bidirectional control characters. JSON output, persisted identities, raw exports and the CLI's own colors are unchanged, and the trusted styling of `renderTable` is untouched.

This absorbs the per-site fixes from @Leon-SK668 (openclaw#184454, openclaw#184379, openclaw#185374, openclaw#186449, openclaw#184396, openclaw#184788, openclaw#184813, openclaw#184394), @huwei-xydt (openclaw#185895, openclaw#185719), @wangmiao0668000666 (openclaw#175600, openclaw#175181, openclaw#175179), @SunnyShu0925 (openclaw#184747), @KrasimirKralev (openclaw#184597) and @arpe1618 (openclaw#150599), whose original commits are kept. Families no PR touched (update, Doctor, install-trust producers and others) are listed under "Not fixed here".

Evidence: 85 built-CLI invocations per ref with crafted control and bidi characters in the reported values, captured as raw stdout bytes. Main printed the raw sequences; this change printed them neutralized, with identical normal colors and unchanged JSON. Details: openclaw#186502 (comment).

Co-authored-by: 胡伟0668000622 <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Leon-SK668 <[email protected]>
Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: SunnyShu <0668000539@local>
Co-authored-by: Krasimir Kralev <[email protected]>
Co-authored-by: arpe1618 <[email protected]>
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

cli CLI command changes P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

2 participants