Skip to content

fix(templates): sanitize remote identity fields in CLI human-readable output - #187666

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/templates-cli-logs-remote-identity-unsanitized-262
Oct 29, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/templates-cli-logs-remote-identity-unsanitized-262

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Templates CLI human-readable reports still interpolate terminal controls from MCP stdio commands and filesystem paths. A schema-valid manifest command or local project path containing ESC/CSI and a newline can emit a live clear-screen sequence and forge additional report lines during preview or validation.

The earlier agent.name inspect trace did not establish this defect: that field was already sanitized on the base by #174989. This PR's proof and scope concern the remaining MCP/path report fields.

User Impact

Human-readable Template authoring, inspection and Add preview reports sanitize external field values using the existing canonical terminal sanitizer. Machine-readable --json values, execution policy, credential-redaction owners and filesystem paths themselves remain unchanged. Ordinary Templates keep their existing behavior.

Why This Change Was Made

Apply sanitizeTerminalText at the existing human-report interpolation boundary across the two Templates command owners. This extends the established rendering policy without rejecting valid manifest data, altering schemas, adding configuration or introducing a new renderer. Existing credential redaction runs before MCP target display sanitization. Contributor commit and credit are retained.

Evidence

Built real-PTY before/after proof, raw JSON hashes and focused regressions.

  • Independently built main and candidate in secretless Node 24.22.1 Linux Docker, using explicit isolated profiles/config/state/database paths and no paid keys, accounts or model.
  • Real PTYs: templates add --dry-run with control-bearing MCP commands/workspace paths and templates validate with a control-bearing project path, twice per command per ref. All four main runs emitted the input ESC [2J sequence and embedded newline; all four candidate runs removed the input sequence and rendered the newline as literal backslash-n. MCP commands were never executed.
  • Complete raw stdout from both commands with --json is byte-identical between refs, without normalization: 3,023 bytes for Add dry-run and 936 bytes for validation. Parsed JSON preserves the original values. Existing MCP target token-argument redaction remains intact.
  • Consolidated the added MCP regression into the existing redaction-preview fixture. It fails on main for the intended unsafe rendering; candidate passes 20 tests /3 affected files. Targeted formatter, oxlint, changed-page MDX and whitespace checks pass.
  • Simplification retains the canonical sanitizer and existing report owners, with no competing abstraction. Against pinned main: production +31/-18 (net +13), tests +5/-5 (net 0), docs +3. No new test file.

Merge Danger

Two-way door: reverting restores previous human-readable rendering. No migration, schema, config, state or public API change. Blast radius is Templates CLI display formatting; machine-readable JSON and template execution remain unchanged.

… output

templates CLI interpolated third-party identity/action fields (agent.name,
MCP server command, package name@version) verbatim into human-readable
runtime.log output. A malicious template's agent name or MCP command
carrying ESC/CSI control bytes or newlines reached the terminal as live
control bytes, enabling terminal injection via 'templates inspect' /
'add --dry-run' previews.

Wrap every external interpolation in sanitizeTerminalText (stripAnsi +
C0/C1/bidi removal). JSON output branches keep raw values. Add a test
covering a malicious MCP server command (schema allows control chars in
the stdio 'command' field).
@clawsweeper

clawsweeper Bot commented Oct 29, 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: S labels Oct 29, 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 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR sanitizes external values in Templates CLI human-readable reports while preserving raw JSON output.

Example: Preview a manifest whose MCP command contains node followed by ESC[2Jevil and a newline before arg.

  • Before: The command clears terminal content and inserts an additional report line.
  • After: The report prints MCP server: nodeevil\narg on one line.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused canonical-owner repair with shipped CLI before/after proof, a consolidated regression, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied isolated Linux Docker proof exercises built Templates Add dry-run and validation commands in real PTYs, showing control-bearing MCP/workspace/project values rendered safely after the fix and complete JSON bytes preserved; it resolves the previous off-target inspect-name proof gap.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Previewing valid third-party Template content or control-bearing paths can alter terminal state and forge report lines.
Reason: The change extends the established terminal-rendering policy without new configuration, schemas, APIs, or execution restrictions.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current terminal-rendering defect with a focused change and no actionable findings; required exact-head CI remains pending.

Priority: P2
Reviewed head: 5328c6d8e6f876b3591d99ac473eb3ecc4e2d11a

Before merge

None.

Findings

None.

Agent review details

How this fits together

Templates CLI commands obtain manifest and project results from existing lifecycle owners, then render either human-readable terminal reports or machine-readable JSON.

flowchart TD
  A[Templates CLI] --> B[Project and manifest owners]
  B --> C[Result values]
  C --> D[Existing terminal sanitizer]
  D --> E[Human reports]
  C --> F[Raw JSON]
Loading

Technical review

Best possible solution:

Retain the existing-owner display sanitization and land once required exact-head checks pass.

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

Current-main source exposes the reported values, and supplied built-CLI traces demonstrate the corresponding before/after failure; this review executed no target code.

Is this the best way to solve the issue?

Applying the canonical sanitizer at existing human-report interpolation boundaries is a small complete repair for the reported fields and preserves machine output and execution semantics.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Project creation, validation, and build reports changes intended behavior with a stated reason (7422222: The author lifecycle introduced readable project and artifact reports; the patch preserves their purpose while making interpolated values safe.)
  • MCP Add preview changes intended behavior with a stated reason (b56006b: Preview exposes MCP commands or URLs before consent; existing credential redaction remains before terminal sanitization.)
  • Dev preview ownership keeps the original intent (5af1093: Private preparation and reporting were consolidated into the command owner without intended behavioral changes.)
  • Templates names and command vocabulary keeps the original intent (d1c8d42: The approved rename established Templates vocabulary while retaining lifecycle and consent behavior.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Gio Della-Libera: Raw commit 7422222 adds src/cli/claws-cli.project.ts:154 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7422222788c4; files: src/cli/claws-cli.project.ts)
  • Peter Steinberger: Raw commit 5af1093 adds src/cli/claws-cli.project.ts:186 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5af109365289; files: src/cli/claws-cli.project.ts)

PR surface

Source +13, Tests 0, Docs +3. Total +16 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 31 18 +13
Tests 1 5 5 0
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 39 23 +16

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Control-bearing MCP commands and filesystem paths can manipulate terminal previews; the repair has a bounded CLI display scope.
  • 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-29T13:19:05.422Z sha 2d593d8 :: needs real behavior proof before merge. :: none

Reviewed October 29, 2026, 11:31 AM ET / 15:31 UTC (Revision 2).

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 29, 2026
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Built Templates CLI proof — changed MCP and path fields

Head: 5328c6d8e6f876b3591d99ac473eb3ecc4e2d11a; pinned main: 01080c52372ed7adba27d4d3c22eb7206ed00197. Contributor commit retained. Both refs were independently installed/built in secretless Linux/arm64 Docker, Node 24.22.1. Only final test consolidation and documentation changed after the candidate build; production behavior is identical to the contributor artifact.

The previous agent.name trace is not evidence for this PR: that inspect field was already sanitized on the base by #174989. The proof below exercises still-broken, changed fields instead.

Used the actual built CLI in real PTYs (pty.fork, 160 columns; each command exits 0), with explicit isolated profiles/config/state paths. The exact binaries printed the resolved config and agent database paths first. Templates Labs was enabled through its existing setting; no account, model, paid key, network fixture or MCP process was needed. All MCP invocations were dry-run previews, never execution of the embedded command.

Shipped commands:

openclaw --profile p187666base templates add <local-manifest> --dry-run --workspace '<control-bearing path>'
openclaw --profile p187666base templates validate '<control-bearing project path>'

Candidate uses the same commands and its own built binary/profile. The local project was created with the shipped templates create command and an explicit valid package name.

Inputs contain actual ESC [2J bytes and embedded newlines in the MCP stdio command and filesystem path. Captures below use <ESC> notation rather than publishing live terminal controls:

main — MCP preview, repetition 1 and 2:
  Workspace: .../preview-workspace<ESC>[2JWORKSPACE
  FORGED-WORKSPACE
  MCP server: node<ESC>[2JMCP
  FORGED-MCP --token ***

candidate — MCP preview, repetition 1 and 2:
  Workspace: .../preview-workspaceWORKSPACE\nFORGED-WORKSPACE
  MCP server: nodeMCP\nFORGED-MCP --token ***

main — project validate, repetition 1 and 2:
  Valid Template project: .../project<ESC>[2JPATH
  FORGED-PATH

candidate — project validate, repetition 1 and 2:
  Valid Template project: .../projectPATH\nFORGED-PATH

All four main PTY runs emitted the live input clear-screen sequence and a forged additional report line. None of the four candidate runs emitted that input sequence; the input newline is represented by literal backslash-n. Ordinary CLI-owned cursor/color controls are not claimed to disappear. The existing MCP target token-argument redaction remains --token *** on both refs.

Raw JSON preservation

Ran both affected commands again with --json through the built binaries, capturing stdout bytes without PTY CRLF conversion. Compared complete bytes, without normalization, field deletion or timestamp masking:

Command Bytes on each ref SHA-256, identical on main and candidate
templates add --dry-run --json 3023 fa6c0d1961ad242f958c8088d60fe004d2444c78b074b8a85b2a33d1bce646ac
templates validate --json 936 15f5bc9dd4a8a6f0424579e66d091253f9ca315eb05bfba3b8bf967131de0774

The parsed JSON retains the original control-bearing field values; only human display is sanitized.

Focused checks and simplification

Consolidated the added MCP regression into the existing credential-redaction preview test, preserving its original assertions and adding the stdio control boundary without a second fixture. Identical final regression on main: 1 fail /13 pass, failing because the MCP command is not safely rendered. Candidate: 20 pass /3 files (templates-cli.test.ts, project and inspect suites). Targeted oxfmt, oxlint (0 warnings/errors), changed-page MDX and whitespace checks passed.

Whole PR: production +31/-18 (net +13); tests +5/-5 (net 0); docs +3. No new renderer, sanitizer, config, execution rule or schema change. The docs clarify human rendering versus raw machine-readable values.

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@obviyus
obviyus merged commit 1e2833c into openclaw:main Oct 29, 2026
132 of 133 checks passed
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in 1e2833c. Thanks @SunnyShu0925. Templates CLI output now escapes untrusted template fields.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
… output (openclaw#187666)

fix(cli): escape untrusted fields in templates add and validate output

openclaw templates add --dry-run and templates validate printed MCP, workspace and project fields from the template raw, so a crafted template could inject terminal control sequences (for example clearing the screen) into human output. These fields now go through the shared terminalText owner, as the other CLI reports do since openclaw#186502. JSON output is unchanged.

Evidence: built templates add --dry-run and templates validate in real PTYs, twice per command per ref. Main printed the control sequences from MCP, workspace and project fields; with this change the clear-screen sequence was removed and embedded newlines were escaped. The full raw --json stdout was byte-identical between refs for both commands. Details: openclaw#187666 (comment).

Thanks @SunnyShu0925.

Co-authored-by: SunnyShu <0668000539@local>
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 docs Improvements or additions to documentation 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