Skip to content

fix(cli): sanitize stored strings in directory, cron show, agents, channels, and sessions output - #123797

Merged
steipete merged 4 commits into
mainfrom
steipete/table-injection-sibling-sweep
Aug 14, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/table-injection-sibling-sweep

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Completes the terminal-injection perimeter opened by #123671. That PR added renderTerminalSafeTable and fixed the exec-approvals tables, but the same asymmetry remained on every sibling surface: cron list sanitized stored strings while its siblings interpolated them raw into terminal output.

Stored or peer-controlled values containing raw ANSI, OSC/BEL, backspace, carriage-return, or embedded newlines reached the operator's terminal unsanitized on:

  • openclaw directory (self/peers/groups/members) — plugin-provided ids and names
  • openclaw cron show — job/owner/model/delivery/error/diagnostic values (exact sibling asymmetry to cron list, same file)
  • openclaw agents list / --bindings / agents set-identity echo — agent id, identity name, workspace path, model
  • openclaw channels list / channels status — account and channel display names
  • openclaw sessions listings and cleanup dry-run — session ids, keys, models, policy keys

Raw escapes from stored data are a real terminal-injection vector: cursor manipulation, terminal-title spoofing, and line-erasure concealment of what the operator is actually approving or inspecting.

Why This Change Was Made

One canonical flow, per Repair Doctrine. Rather than adding per-command scrubbers, every surface now routes through the boundary that already exists:

  • Table-backed surfaces (directory) swap renderTable → renderTerminalSafeTable (added in fix(cli): approval listings no longer execute stored terminal escapes #123671).
  • Bespoke string formatters apply the same sanitizeTerminalText helper at the value-interpolation boundary — in cron show via a local showValue that also folds in the existing stringifyCell null handling, replacing hand-rolled ?? "-" chains.

renderTable itself is untouched, so its deliberate trusted-ANSI / OSC-link / multiline contract (asserted by packages/terminal-core/src/table.test.ts) still holds for styled consumers. JSON output is untouched on every surface and stays byte-exact.

User Impact

Operators inspecting cron jobs, agents, channels, directory entries, or sessions can no longer have their terminal manipulated by strings that arrived through a plugin, a peer, or an earlier agent run. Printable Unicode still renders; CR/LF/tab become visible escapes. Machine-readable --json output is unchanged, so scripts are unaffected.

Evidence

  • 55 tests pass across the six touched suites, including a per-surface regression asserting no raw ESC and no row injection in human output plus exact JSON: node scripts/run-vitest.mjs src/cli/directory-cli.test.ts src/cli/cron-cli/shared.test.ts src/commands/agents.commands.list.test.ts src/commands/channels.list.test.ts src/commands/sessions.test.ts src/commands/agents.identity.test.ts
  • Follows the reference implementations: cron list (src/cli/cron-cli/shared.ts) and the approvals tables from fix(cli): approval listings no longer execute stored terminal escapes #123671.
  • Deferred as named follow-up (higher-scope styled mixed content, deliberately not in this PR): message/log replay of remote peer text in src/commands/message-format.ts, src/cli/logs-cli.ts, src/commands/channels/logs.ts.

Follow-up to #123671.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 14, 2026 18:51
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes commands Command implementations size: M maintainer Maintainer-authored PR labels Aug 14, 2026
@steipete
steipete force-pushed the steipete/table-injection-sibling-sweep branch from d50b665 to d5e1969 Compare August 14, 2026 19:06
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 14, 2026, 3:28 PM ET / 19:28 UTC.

ClawSweeper review

What this changes

This PR sanitizes several stored or plugin-provided values in human-readable CLI output while retaining raw JSON output.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open: the prior P1 remains unresolved because channel-status errors and warnings still reach human terminal output without sanitization.

Priority: P1
Reviewed head: 1f4df4f84ebf105b15b78ad448a2db48570319b6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has useful focused coverage but retains the prior P1 terminal-safety hole.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-labeled PR is not subject to the external-contributor proof gate; its focused tests remain supplemental evidence.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-labeled PR is not subject to the external-contributor proof gate; its focused tests remain supplemental evidence.
Evidence reviewed 6 items PR-head label sanitization: The branch sanitizes channel labels, account IDs, and account names, but this is only one part of the rendered account line.
Raw status fragments remain: stateReason and lastError are interpolated into status bits without sanitizeTerminalText, and the complete line joins those bits into terminal text.
Gateway warnings remain raw: Gateway-provided warning strings are sliced and directly appended to terminal lines; account status rendering also feeds the same unsanitized bit helpers.
Findings 1 actionable finding [P1] Sanitize every dynamic channel-status fragment
Security Needs attention Channel status retains terminal-injection paths: Untrusted error and warning strings remain interpolated into human terminal output after the new label sanitizer, leaving the stated security boundary incomplete.

How this fits together

CLI commands format stored configuration, plugin metadata, and Gateway status into either terminal text or JSON. The changed terminal formatting paths feed operator-facing inspection commands, while JSON remains the machine-readable path.

flowchart LR
  A[Stored config and plugin data] --> C[CLI formatters]
  B[Gateway status payload] --> C
  C --> D[Labels and status fragments]
  D --> E[Human terminal output]
  C --> F[JSON output]
Loading

Before merge

  • Sanitize every dynamic channel-status fragment (P1) - The changed formatter protects only labels. stateReason and lastError still enter bits verbatim, and Gateway warnings are also appended directly before the account line is logged. A hostile plugin or runtime error can therefore still inject terminal controls; sanitize these unstyled fragments and cover error and warning text in the regression.
  • Resolve security concern: Channel status retains terminal-injection paths - Untrusted error and warning strings remain interpolated into human terminal output after the new label sanitizer, leaving the stated security boundary incomplete.
  • Resolve merge risk (P1) - Hostile channel state reasons, runtime errors, and Gateway warnings can still alter terminal presentation despite the PR's security goal.
  • Resolve merge risk (P1) - The PR adds net production code while leaving the shared channel status boundary incomplete.
  • Complete next step (P2) - This maintainer-labeled PR needs its existing P1 addressed on the author branch; it is not a ClawSweeper repair-dispatch candidate.

Findings

  • [P1] Sanitize every dynamic channel-status fragment — src/commands/channels/shared.ts:60
  • [medium] Channel status retains terminal-injection paths — src/commands/channels/shared.ts:91
Agent review details

Security

Needs attention: The branch improves terminal safety but leaves reachable channel-status text unsanitized.

PR surface

Source +11, Tests +265. Total +276 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 6 52 41 +11
Tests 9 266 1 +265
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 318 42 +276

Review metrics

Metric Value Why it matters
Production versus test LOC production +52/-41 (net +11); tests +266/-1 (net +265) The security-boundary growth is only justified if the remaining shared channel-status output paths are covered.

Stored data model

Persistent data-model change detected: serialized state: src/commands/agents.identity.test.ts, serialized state: src/commands/channels.list.test.ts, serialized state: src/commands/channels.status.command-flow.test.ts, serialized state: src/commands/sessions.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete terminal-safe channel status (recommended)
    Sanitize every dynamic channel-status fragment and add hostile error and warning regressions before merging.

Technical review

Best possible solution:

Complete the channel text boundary by sanitizing dynamic bit values and Gateway-only warning or issue fields before human rendering, preserving raw JSON exactly.

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

Yes—source-reproducible with high confidence: hostile stateReason, lastError, or Gateway warning text is interpolated into human output without the sanitizer; no live command was run in this read-only review.

Is this the best way to solve the issue?

No—the label-only repair is too narrow. Sanitizing dynamic values at the shared status-fragment and Gateway-rendering boundaries preserves intentional styling and JSON while covering the remaining injection paths.

Full review comments:

  • [P1] Sanitize every dynamic channel-status fragment — src/commands/channels/shared.ts:60
    The changed formatter protects only labels. stateReason and lastError still enter bits verbatim, and Gateway warnings are also appended directly before the account line is logged. A hostile plugin or runtime error can therefore still inject terminal controls; sanitize these unstyled fragments and cover error and warning text in the regression.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3289e08c3005.

Labels

Label justifications:

  • P1: Plugin or Gateway-controlled status text can still reach an operator terminal unsanitized.
  • merge-risk: 🚨 security-boundary: Merging would present an incomplete terminal-injection fix while leaving reachable hostile status text raw.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-labeled PR is not subject to the external-contributor proof gate; its focused tests remain supplemental evidence.

Evidence

Security concerns:

  • [medium] Channel status retains terminal-injection paths — src/commands/channels/shared.ts:91
    Untrusted error and warning strings remain interpolated into human terminal output after the new label sanitizer, leaving the stated security boundary incomplete.
    Confidence: 0.99

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the current-main commit blamed for the shared channel-status fragment formatter and is also the author of this follow-up. (role: recent channel-status contributor; confidence: high; commits: f65a6f81de6d, 1f4df4f84ebf; files: src/commands/channels/shared.ts, src/commands/channels/status.runtime.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Sanitize dynamic channel status bits and Gateway warning or issue text, then add hostile terminal-output regressions for those paths.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-14T19:11:09.961Z sha d5e1969 :: found issues before merge. :: [P1] Sanitize every dynamic channel-status fragment

@steipete
steipete merged commit 36c440a into main Aug 14, 2026
177 checks passed
@steipete
steipete deleted the steipete/table-injection-sibling-sweep branch August 14, 2026 19:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 15, 2026
…annels, and sessions output (openclaw#123797)

* fix(cli): sanitize stored strings in table surfaces

* fix(cli): use resolved identity agent id

* test(cli): keep cron delivery status typed

* test(cli): assert agent JSON non-sanitization without path equality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant