Skip to content

fix(cli): sanitize untrusted pairing request fields before rendering - #175179

Closed
wangmiao0668000666 wants to merge 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/pairing-report-terminal-controls
Closed

wangmiao0668000666 wants to merge 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/pairing-report-terminal-controls

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw pairing list prints a pending request's sender id verbatim, so an id carrying terminal control sequences (ESC/BEL) changes the operator's terminal while inspecting untrusted senders — requests exist precisely because the sender is not trusted yet.

User Impact

User impact: the pairing table renders every cell literally without control sequences, and --json keeps the raw values for scripts.

Why This Change Was Made

Classification: behavior-completing.

This table is the untrusted-input case the terminal renderer already anticipates: packages/terminal-core/src/table.ts ships renderTerminalSafeTable ("Render untrusted single-line values without changing renderTable's trusted ANSI contract") next to renderTable, and pairing list was the remaining caller feeding remote sender metadata into the trusted renderer. The swap is one call; no new helper, option, or output format.

Precedent: #172872, #172873, #174989 (same shape at other human report boundaries).

Revision 2026-10-20 — reopened, rebased, re-proved

Rebased onto current main (2d03d5632a6). The branch's original parent was no longer in main's history, so the commit was replayed with git rebase --onto; the production hunk applied unchanged (renderTable → renderTerminalSafeTable, plus its import). The test was re-added against the file's current shape (main restructured pairing-cli.test.ts into top-level beforeEach helpers and a runPairing(command, ...args) fixture), and it asserts the absence of the control bytes, not just the presence of the visible text.

Fresh evidence on this head:

Cell Base (main) Head (c4e3a49906d)
src/cli/pairing-cli.test.ts 1 failed / 13 passed (14) — strips terminal controls from pairing ids and metadata 14 passed (14)
openclaw pairing list --channel telegram, raw bytes 1507 bytes, ESC ×1, BEL ×1 — the OSC title sequence reaches the terminal 1497 bytes, ESC ×0, BEL ×0
Visible text in that same output PAIR_MARKER present PAIR_MARKER present

The third row is the point: the sender-controlled text still renders (PAIR_MARKER), only the ESC ]0; … BEL wrapper is removed — this is sanitization of a render path, not dropping the field.

Proof setup: one genuine pending request seeded with the repo's own upsertChannelPairingRequest into an isolated OPENCLAW_STATE_DIR, senderId = snd\x1b]0;pwned\x07PAIR_MARKER; the command was run through the repo's CLI entry on both trees with the same state dir. Byte counts and control-byte counts were taken from the captured output, not from a parsed render.

Evidence

  • Base a45bf3ceb96, head f799dafc9bfe; secretless Linux container, Node 24.18.0, isolated HOME/OPENCLAW_STATE_DIR.
  • Fixture: two pending telegram requests created through the production ingress owner upsertChannelPairingRequest — one with meta.senderId = "snd\^[]0;pwned\^GPAIR_MARKER", one plain.
  • Real entry, identical command on both revisions: node --import ./scripts/tsx.mjs src/entry.ts pairing list --channel telegram
base this head
rendered telegramUserId cell snd]0;pwnedPAIR_MARKER sndPAIR_MARKER
unsafe control chars in the report (C0 minus tab/LF/CR, DEL, C1) 2 (0x1b, 0x07) 0
plain request row plain-sender plain-sender (unchanged)

The --json branch returns { channel, requests } before the table is built, so structured output is untouched by this diff.

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

base:  × strips terminal controls from pairing ids and metadata
       AssertionError: expected 'Pairing requests (2)…' not to match /\p{Cc}/u
head:  ✓ strips terminal controls from pairing ids and metadata

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

Not tested: requests whose code or requested timestamps are remote-controlled (both are generated locally by the pairing owner).

@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

Render pending pairing requests through the existing terminal-safe table renderer while preserving raw JSON output.

Example: A pending request has senderId "snd\u001b]0;pwned\u0007PAIR_MARKER".

  • Before: The pairing list emits ESC and BEL bytes that can change the terminal title.
  • After: The sender displays as sndPAIR_MARKER without executing the control sequence.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, worthwhile repair with shipped CLI proof, an observable regression test, and no actionable findings; pending CI is a workflow gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The contributor records the pairing CLI running against an isolated state directory seeded through upsertChannelPairingRequest on the base and current head: the hostile sender's ESC/BEL bytes disappear while visible text remains, supported by a red/green CLI regression.
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 pending sender can execute sender-controlled terminal sequences in the operator's terminal.
Reason: The patch applies an established untrusted-display contract to an exposed caller without adding settings, state, or competing sanitization policy.

Merge readiness

✅ Ready for maintainer review

This PR fixes a concrete terminal-control injection path still present on current main, using the existing sanitization owner with no actionable findings; exact-head CI remains pending.

Priority: P2
Reviewed head: c4e3a49906dde1533b3b4aa9603aaf49fa89b021

Before merge

None.

Findings

None.

Agent review details

How this fits together

The pairing CLI reads pending requests from the existing state owner and returns either structured JSON or a human-readable terminal table.

flowchart LR
  A[Channel pairing ingress] --> B[Pairing state owner]
  B --> C[Pairing list CLI]
  C --> D[Raw JSON output]
  C --> E[Terminal safe renderer]
  E --> F[Operator terminal]
Loading

Technical review

Best possible solution:

Merge the existing safe-renderer substitution after the exact-head CI gate passes.

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

Current-main source exposes the unsafe rendering path, and contributor-supplied before/after CLI results demonstrate it with a genuine pending request; this review executed no target code.

Is this the best way to solve the issue?

The smallest complete fix is to reuse the established safe renderer at the human-output boundary, preserving canonical request data, JSON, and approval semantics.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Pairing table output keeps the original intent (2cd62f9: Present pending pairing requests in a structured table with consistent columns and themed headings.)
  • Raw sender identity display keeps the original intent (a968d15: Retain raw sender IDs for display while pairing identities remain workspace-qualified.)
  • Trusted and untrusted terminal rendering keeps the original intent (fix(cli): approval listings no longer execute stored terminal escapes #123671: Provide an explicit safe-rendering boundary without changing the trusted renderer's styling, hyperlink, and multiline contract.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 2cd62f9 adds src/cli/pairing-cli.ts:85 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2cd62f94a5cf; files: src/cli/pairing-cli.ts)

PR surface

Source +3, Tests +17. Total +20 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 5 2 +3
Tests 1 17 0 +17
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 22 2 +20

Root-cause cluster

Relationship: canonical
Canonical: #175179
Summary: This PR carries the actionable chat-pairing terminal-control repair; the earlier identical submission is closed unmerged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded operator-facing terminal-control injection path has a focused repair without changing pairing permissions or stored identities.
  • 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 (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-17T07:30:11.723Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T08:44:42.572Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T09:02:35.822Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T10:12:08.913Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T10:37:10.706Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T10:57:30.036Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T11:13:44.733Z sha f799daf :: needs maintainer review before merge. :: none
  • reviewed 2026-10-17T11:51:33.424Z sha f799daf :: needs maintainer review before merge. :: none

Reviewed October 20, 2026, 9:15 AM ET / 13:15 UTC (Revision 12).

@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
@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/pairing-report-terminal-controls branch from f799daf to c4e3a49 Compare October 20, 2026 13:05
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 20, 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 20, 2026
obviyus added a commit that referenced this pull request Oct 28, 2026
…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]>
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks @wangmiao0668000666. This is now fixed at the root in #186502 (3bcca4f), which routes the remaining CLI reports through the shared terminalText owner from terminal-core. Your commit is kept in that merge and you're credited as co-author, so I'm closing this one as covered. For new output sites, please pass untrusted values through terminalText (or displayPath for paths) rather than opening a PR per command.

@obviyus obviyus closed this Oct 28, 2026
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for folding these into the shared terminalText sweep in #186502 and keeping the commit co-authored in the merge. Understood: new output sites should pass untrusted values through terminalText (or displayPath for paths) instead of per-command PRs. Appreciate the root fix.

@wangmiao0668000666
wangmiao0668000666 deleted the fix/pairing-report-terminal-controls branch October 28, 2026 06:13
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…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]>
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: XS 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