Repository navigation
fix(templates): sanitize remote identity fields in CLI human-readable output - #187666
Conversation
… 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).
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherTemplates 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +13, Tests 0, Docs +3. Total +16 across 4 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 29, 2026, 11:31 AM ET / 15:31 UTC (Revision 2). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Built Templates CLI proof — changed MCP and path fieldsHead: 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 ( 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 Inputs contain actual ESC 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 Raw JSON preservationRan both affected commands again with
The parsed JSON retains the original control-bearing field values; only human display is sanitized. Focused checks and simplificationConsolidated 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 ( 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in 1e2833c. Thanks @SunnyShu0925. Templates CLI output now escapes untrusted template fields. |
… 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]>
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.nameinspect 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
--jsonvalues, execution policy, credential-redaction owners and filesystem paths themselves remain unchanged. Ordinary Templates keep their existing behavior.Why This Change Was Made
Apply
sanitizeTerminalTextat 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.
templates add --dry-runwith control-bearing MCP commands/workspace paths andtemplates validatewith a control-bearing project path, twice per command per ref. All four main runs emitted the input ESC[2Jsequence and embedded newline; all four candidate runs removed the input sequence and rendered the newline as literal backslash-n. MCP commands were never executed.--jsonis 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.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.