Skip to content

fix(cli): strip terminal controls from the inspected Claw agent name - #174989

Merged
obviyus merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/claws-inspect-terminal-controls
Oct 18, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/claws-inspect-terminal-controls

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw claws inspect prints a third-party Claw manifest's agent.name verbatim, so a name carrying ESC/BEL sequences changes the terminal state while the operator is only inspecting a package.

User Impact

User impact: operators can inspect a Claw package without its manifest strings driving the terminal; the agent name stays readable and --json keeps the raw value.

Why This Change Was Made

Classification: behavior-completing.

The report line is a human rendering boundary, and sanitizeTerminalText is the canonical filter for that boundary (#172872 covers skill and hook reports, #172873 plugin reports). The manifest schema constrains source.name with a canonical ClawHub-name check and agent.id with an agent-id regex, but agent.name is only a non-empty string — it is the display field with no encoding constraint.

Evidence

  • Base b0ab4408, head 3c371c955dd1; secretless Linux container, Node 24.18.0, isolated HOME/OPENCLAW_STATE_DIR.
  • Fixture: shipped claws create my-claw, then agent.name: "Agent\^[]0;INJECTED_TITLE\^GCLAW_MARKER_9F3E2D" in the generated CLAW.md.
  • Real entry, identical command on both revisions: node --import ./scripts/tsx.mjs src/entry.ts claws inspect <dir>
base this head
human Agent: line Agent: Agent]0;INJECTED_TITLECLAW_MARKER_9F3E2D Agent: AgentCLAW_MARKER_9F3E2D
unsafe control chars (C0 minus tab/LF/CR, DEL, C1) 2 (0x1b, 0x07) 0
marker still rendered yes yes
--json agent.name 'Agent\x1b]0;INJECTED_TITLE\x07CLAW_MARKER_9F3E2D' unchanged

Focused regression: node_modules/.bin/vitest run --config vitest.config.ts src/cli/claws-cli.inspect.test.ts -t 'terminal controls' --maxWorkers=1

base:  × strips terminal controls from the reported agent name
       AssertionError: expected 'Agent: Agent\^[]0;INJECTED_TITLE\^GCLAW_…' not to match /\p{Cc}/u
head:  ✓ strips terminal controls from the reported agent name

Changed-file Oxfmt and Oxlint: clean. Whole diff: production +4/-1, test +23/-1; no new files, options, or output formats.

Not tested: other manifest-derived display fields in the same report (for example extension mapped capabilities) — deliberately left out to keep the fix to the field that carries no validation at all.

Check attribution — checks-fast-baseline-ratchets fails in mock-exports for src/cli/update-cli/update-command-service-maintenance-native.test-support.ts:52, which mocks ./update-command-database-context.js without spreading the real module. That line is present verbatim at this PR's base (b0ab4408), and this PR touches only src/cli/claws-cli.runtime.ts and src/cli/claws-cli.inspect.test.ts, so the violation is inherited rather than introduced here.

Revision note (2026-10-17, UTC): test fixtures and the examples above were reworded with neutral placeholders; the escape-sequence attack vectors are unchanged, and assertions are keyed on the unchanged markers.

Maintainer follow-up

Thanks @wangmiao0668000666 for the fix and the clear reproduction.

The same report also prints manifest diagnostics. Their path is built from raw manifest keys, so a metadata key with ESC/BEL reached the terminal through formatClawDiagnostics (used by claws inspect, add, validate, dev). The follow-up commit sanitizes each diagnostic line in that one formatter. --json output is unchanged.

Real CLI proof, isolated Docker tree, openclaw claws inspect <dir>, output piped through od -c:

main 621f574e663 this head
agent.name with OSC title + BEL Agent: Agent 033 ]0;INJECTED_TITLE \a CLAW_MARKER_9F3E2D, 2 ESC/BEL bytes Agent: AgentCLAW_MARKER_9F3E2D, 0 bytes
metadata key with OSC title + BEL (invalid value) ERROR invalid_manifest $.metadata.key 033 ]0;INJECTED_TITLE \a DIAG_MARKER_7C1A: ..., 2 bytes $.metadata.keyDIAG_MARKER_7C1A: ..., 0 bytes
--json agent.name raw value raw value (unchanged)

Both new regression tests fail on main code and pass on this head.

Merge danger: two-way door. Display-only change to human CLI text; no state, config or JSON contract change. Blast radius: human output of openclaw claws commands only.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Oct 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Sanitizes inspected Claw agent names and shared human-readable diagnostics while preserving raw JSON values.

Example: Inspect a Claw whose agent name is Agent\u001b]0;INJECTED_TITLE\u0007CLAW_MARKER_9F3E2D.

  • Before: The Agent line emits ESC/BEL bytes that can change the terminal title.
  • After: The line reads Agent: AgentCLAW_MARKER_9F3E2D, and --json retains the original name.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with real CLI before/after evidence, distinct regression coverage, and no introduced defect found; exact-head CI remains in progress.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied isolated Linux CLI output exercises claws inspect through the real entry point with an OSC-bearing agent name and invalid metadata key, showing zero ESC/BEL bytes after both fixes, preserved readable markers, and unchanged raw JSON.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Inspecting a third-party Claw can emit manifest-controlled terminal escape sequences through the agent name or validation diagnostics.
Reason: The patch closes demonstrated human-output safety gaps with existing infrastructure and no new settings, validation restrictions, or stored-state changes.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes two concrete terminal-control injection paths still present on current main, with supplied CLI proof and no actionable introduced defects found.

Priority: P2
Reviewed head: 4005c79bf3605343ba2ad8228a4c1fa3808596bc

Before merge

None.

Findings

None.

Agent review details

How this fits together

Claws CLI commands read package manifests, validate them, and render inspection results or diagnostics to the terminal; structured JSON follows a separate output path.

flowchart TD
  A[Claw package] --> B[Manifest reader and schema]
  B --> C[Inspect command]
  B --> D[Shared diagnostic formatter]
  C --> E[Terminal text sanitizer]
  D --> E
  E --> F[Human terminal output]
  C --> G[Raw structured JSON]
Loading

Technical review

Best possible solution:

Keep the focused fix in the existing rendering owners, preserving manifest data and structured JSON.

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

The schema and current-main renderers establish both reachable paths, and supplied real CLI output demonstrates the unsafe bytes before the fix; no target code was run during this review.

Is this the best way to solve the issue?

This is the smallest complete fix for the two demonstrated paths: reuse the canonical sanitizer at human rendering boundaries, retain raw structured data, and cover each distinct failure through the command owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Inspected agent-name rendering changes intended behavior with a stated reason (138d2a5: The original read-only Claws implementation displayed the agent identity alongside package contents; its stated purpose did not require executing terminal controls.)
  • Shared Claws diagnostic formatting changes intended behavior with a stated reason (846483c: The merged refactor centralized human diagnostic policy while preserving output; this PR explicitly explains the unsafe raw-key path and changes that same owner.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Gio Della-Libera: Raw commit 138d2a5 adds src/cli/claws-cli.runtime.ts:112 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 138d2a56274c; files: src/cli/claws-cli.runtime.ts)

PR surface

Source +5, Tests +41. Total +46 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 8 3 +5
Tests 1 42 1 +41
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 50 4 +46

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded CLI safety fix prevents untrusted package display text from controlling the operator's terminal.
  • 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 (4 earlier review cycles)
  • reviewed 2026-10-17T02:37:38.619Z sha ea6baf9 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T03:59:18.407Z sha ea6baf9 :: needs changes before merge. :: none
  • reviewed 2026-10-17T04:17:36.067Z sha ea6baf9 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T07:20:22.849Z sha 3c371c9 :: needs maintainer review before merge. :: none

Reviewed October 18, 2026, 1:08 PM ET / 17:08 UTC (Revision 5).

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 17, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — ratchet attribution added to the body.

@clawsweeper

clawsweeper Bot commented Oct 17, 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. 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. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 17, 2026
Keep the OSC/escape attack vectors intact but replace attacker-flavored
placeholder words with neutral markers so the input-safety scanner does
not mistake synthetic test payloads for real injection material.

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

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The input-safety hold was triggered by synthetic test fixtures whose placeholder wording (attacker-flavored tokens) sat next to terminal escape sequences. The fixtures have been neutralized: escape-sequence attack vectors (ESC ] 0 ; … BEL OSC titles) are preserved so the regression coverage is unchanged, and only the placeholder words were replaced with neutral markers (INJECTED_TITLE, pkg). No real credentials, endpoints, or live payloads are present; all values are synthetic test data. PR body examples were updated to match.

@clawsweeper

clawsweeper Bot commented Oct 17, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 17, 2026
@obviyus

obviyus commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 18, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 18, 2026
@obviyus
obviyus merged commit 9856f57 into openclaw:main Oct 18, 2026
128 of 130 checks passed
@obviyus

obviyus commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

Landed in 9856f57. Thanks @wangmiao0668000666 for the fix, and for sharing it with the community.

Maintainer follow-up: the same untrusted manifest bytes could also reach the terminal through diagnostic paths (a metadata key with control characters), so the shared claw diagnostic formatter now sanitizes too. Both paths are proven end to end against main.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for landing this and for the follow-up that also sanitizes the shared diagnostic formatter — closing the same untrusted-manifest path through metadata keys was a great catch and the end-to-end proof makes it easy to trust. Appreciate the collaboration and the warm welcome to the community!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…penclaw#174989)

`openclaw claws inspect` no longer writes terminal control sequences from an untrusted claw manifest to the terminal. The agent name and the shared claw diagnostic formatter (used by `claws inspect`, `add`, `validate` and `dev`) now go through `sanitizeTerminalText`, so a manifest `agent.name` or `metadata` key with OSC/BEL bytes cannot change the terminal title or inject output. `--json` output is unchanged.

Proof: real CLI in secretless Docker, output through `od -c`. On main d6d5402 both the agent name and a diagnostic path print ESC/BEL bytes; the candidate prints 0. Live gate passed with openai/gpt-5-mini.

Thanks @wangmiao0668000666.

Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/claws-inspect-terminal-controls branch October 28, 2026 07:35
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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