Repository navigation
fix(sessions): escape terminal controls in cleanup store headers - #184747
SunnyShu0925 wants to merge 3 commits into
Conversation
Human-readable sessions cleanup output inserted the store path and agent id verbatim into runtime.log, so a store path carrying C0/C1 terminal controls (ESC color sequences, BEL, newline/tab) could forge terminal output and break single-line formatting. renderAppliedResult and the dry-run path now route both the store path and agent id through sanitizeTerminalText, matching the existing label handling in the same file and the store-header fix in sessions.ts.
|
🦞👀 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 changesSanitize agent IDs and store paths in human-readable session-cleanup headers. Example: Run cleanup with a SQLite filename containing ESC[31m and BEL between “sess” and “ions.sqlite”.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR: it fixes raw terminal-control output still present on current main, using the existing sanitizer without changing cleanup behavior; no actionable defects found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe sessions cleanup CLI receives local previews or applied cleanup summaries and renders human-readable headers or unchanged JSON results. flowchart TD
A[Cleanup CLI options] --> B[Cleanup command]
B --> C[Local cleanup or Gateway]
C --> D[Cleanup summaries]
D --> E[Sanitized human headers]
D --> F[JSON output]
Technical reviewBest possible solution: Merge the focused sanitizer fix when the required current-head checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source directly emits raw header values, and the contributor supplies before/after CLI output; no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete fix: sanitize at both existing presentation owners while preserving selection, persistence, and JSON output. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a468f8dfa37b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +48. Total +48 across 2 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 (4 earlier review cycles)
Reviewed October 26, 2026, 7:16 PM ET / 23:16 UTC (Revision 5). |
The dry-run assertion used vi.clearAllMocks() then a whole-array find, but clearAllMocks does not clear the plain logs array, so the find could match the apply lane's own sanitized Session store: line (stale output). Record the log length before the dry-run invocation and search only the entries appended by it.
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…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]>
|
Thanks @SunnyShu0925. This is now fixed at the root in #186502 (3bcca4f), which routes the remaining CLI reports through the shared |
…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]>
What Problem This Solves
Fixes terminal actions and forged header lines when a session store path (or agent id) passed to
openclaw sessions cleanupcontains control characters. The human-readableSession store:andAgent:headers were interpolated raw, so an ANSI escape or bell byte in the store selector could reach the terminal.User Impact
openclaw sessions cleanuphuman output now safely renders the store path and agent id inAgent:/Session store:headers. JSON output and store selection are unchanged; the underlying path is not modified.Why This Change Was Made
The file already imports the canonical terminal sanitizer and applies it to the
Session label:header in the same renderer. This change applies that same policy to theAgent:andSession store:headers at their existing output owners, so both the gateway-delegated apply result and the local dry-run preview follow one consistent rule.Evidence
Real CLI proof — both changed renderers (shipped binary, current head
81e5197). The dry-run preview and the apply result each render theSession store:header through a changed output owner; both are proven through the shipped CLI with the same control-char store path (saved assess+ESC[31mANSI red +ions+BEL+.sqlite), A/B: sanitizer wired (post-fix) vs unwrapped at the same owner (pre-fix). Both captures were recorded on the current head (81e5197); the production patch is byte-identical across9d2c650→81e5197(later commits only harden the regression test), so the post-fix output is the current head's behavior.Dry-run preview (
openclaw sessions cleanup --dry-run, control-charsession.storeconfig path that does not exist on disk, so it resolves as an in-memory preview):Session store:header (raw terminal)/tmp/oc-proof-184747/agents/main/agent/sess^[[31mions^G.sqlite/tmp/oc-proof-184747/agents/main/agent/sessions.sqliteApply result (
openclaw sessions cleanup --store <real-init-store-with-control-chars> --enforce, stays local and rendersrenderAppliedResult):Session store:header (raw terminal)/tmp/oc-proof-184747/agents/main/agent/sess^[[31mions^G.sqlite/tmp/oc-proof-184747/agents/main/agent/sessions.sqliteBoth runs reach completion (dry-run:
Maintenance mode: enforce/Entries: 0 -> 0; apply:Applied maintenance. Current entries: 0, exit 0). Pre-fix passes^[[31m/^Gthrough verbatim; post-fix strips the control bytes and renders cleansessions.sqlite(cat -v confirms no^[/^G). TheAgent:header is the same expression shape (Agent: ${sanitizeTerminalText(summary.agentId)}) at the same output owners; a multi-store dry-run proves a control-bearing agent id is also sanitized in that header.Regression (P3 + Agent-header coverage). Two stale/missing assertions were hardened. (1) The dry-run store assertion previously used
vi.clearAllMocks()then a whole-arrayfind— butclearAllMocks()does not clear the plainlogsarray, so the assertion could read the apply lane's own sanitized line. It now recordsappliedLength = logs.lengthbefore the dry-run invocation and searches onlylogs.slice(appliedLength). (2) TheAgent:header was not asserted at all; a multi-store dry-run (previewResults.length > 1) now feeds a control-bearing agent id and asserts the rendered header is clean. Both verified bidirectional: with the respective dry-run sanitizer removed, the store-path assertion fails (expected "Session store: sessions-café\noperator-forged\tend\rrow" not to match /\p{Cc}/u) and the Agent-header assertion fails (expected 'Agent: worker\u001b[31m\u0007main' not to match /\p{Cc}/u); restored, all 14 tests pass.git diff --checkpass. Production change is net-zero LOC: four existing output expressions are wrapped in the already-imported sanitizer.src/commands/sessions-cleanup.ts. The upstream family PR fix(sessions): escape terminal controls in store headers #184139 (merged) modifiedsessions.tsandsecrets-store-cli.ts, not this file.