Skip to content

fix(cli): approval listings no longer execute stored terminal escapes - #123671

Merged
steipete merged 2 commits into
mainfrom
steipete/render-injection-sweep
Aug 14, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/render-injection-sweep

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators inspecting stored exec approval policies could execute terminal control sequences when an allowlist pattern, agent key, path, or native-rule field contained ANSI or C0/C1 control characters.

The supported approvals allowlist add path accepted these values and both its confirmation output and approvals get rendered them through the trusted-ANSI table primitive. JSON output correctly preserved and escaped the stored values.

Why This Change Was Made

Adds an explicit terminal-safe table entry point that sanitizes every header and cell before delegating to the existing layout engine. All approval tables now use that boundary, while the low-level table renderer keeps its deliberate trusted styling, hyperlink, and multiline contract.

User Impact

Approval listings now display hostile newlines, tabs, and carriage returns as visible escapes, remove terminal escape/control sequences, and preserve printable Unicode such as 🦞. Machine-readable JSON remains exact.

Evidence

  • Supported scratch-profile reproduction before the fix: 3 ESC bytes, 1 BEL, 1 backspace, and 1 tab reached human output; the embedded newline expanded the row.
  • Same reproduction after the fix: 0 ESC, BEL, backspace, carriage-return, or tab bytes; \n, \t, and \r remained visible; 🦞 remained intact.
  • Regression test first failed on the raw-control assertion, then passed after routing approval tables through the safe renderer. JSON exactness is asserted in the same test.
  • Focused Vitest: 89 tests passed across the terminal table and both exec-approvals suites.
  • Exact-scope node scripts/check-changed.mjs: passed formatting, typechecks, lint, dead-code, dependency, database, import-cycle, and architecture guards on the rebased head.
  • Codex autoreview: clean, no accepted/actionable findings.
  • Production LOC: +27/-7 (net +20) for the explicit reusable terminal-safety boundary and six approval-table call sites. Tests: +32/-0.

@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.

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Aug 14, 2026
@steipete
steipete marked this pull request as ready for review August 14, 2026 13:34
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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, 9:41 AM ET / 13:41 UTC.

ClawSweeper review

What this changes

The PR adds a terminal-safe table renderer and uses it for human-readable exec-approval CLI tables while leaving JSON output unchanged.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this maintainer-labelled PR open: it closes a real terminal-safety gap, but its safe-table wrapper also flattens the Effective Policy table’s intentional multiline cells into literal escapes.

Priority: P2
Reviewed head: e890ca9b6e4e2bdb0507f2160250a785cb847943

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The security direction and supplied reproduction are useful, but the patch has a concrete P2 terminal-output compatibility regression.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records a before/after terminal reproduction and JSON-preservation check.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records a before/after terminal reproduction and JSON-preservation check.
Evidence reviewed 6 items Current unsafe path: Current main sends all six exec-approval human tables to the ANSI-capable renderer, including Effective Policy and stored allowlist values.
Introduced output regression: The proposed safe renderer sanitizes every table cell; Effective Policy deliberately creates multiline Requested, Host, and Effective cells, so its line breaks become visible literal escapes.
Existing renderer contract: The terminal-table test requires explicit cell newlines to render on adjacent table lines, confirming that multiline cells are intentional supported behavior.
Findings 1 actionable finding [P2] Preserve the Effective Policy table’s intentional line breaks
Security None None.

How this fits together

The exec-approval CLI reads local, gateway, or node approval policies and renders them for operators. Its table layer turns policy fields into terminal output, while JSON remains the machine-readable path.

flowchart LR
  A[Stored approval policy] --> B[Exec approvals CLI]
  B --> C{Output mode}
  C -->|Human| D[Terminal table renderer]
  C -->|JSON| E[Exact JSON output]
  D --> F[Operator terminal]
  E --> G[Automation client]
Loading

Before merge

  • Preserve the Effective Policy table’s intentional line breaks (P2) - renderEffectivePolicy deliberately builds Requested, Host, and Effective with newline-separated fields, and renderTable has an explicit multiline-cell contract. Passing all cells through sanitizeTerminalText turns those separators into literal \n, flattening every human Effective Policy row. Sanitize untrusted approval fields before composition (or add an explicit safe-cell boundary) and cover this layout alongside the hostile-value regression.
  • Resolve merge risk (P1) - Merging as written makes the Effective Policy view harder to scan by replacing its intended table line breaks with literal \n text.
  • Resolve merge risk (P1) - Production code grows by 20 net lines; the new generic table boundary should not remain if a narrower untrusted-field boundary preserves the existing renderer contract.
  • Complete next step (P2) - Address the concrete P2 finding before merge; the maintainer label keeps this security-sensitive CLI path under explicit human review.

Findings

  • [P2] Preserve the Effective Policy table’s intentional line breaks — src/cli/exec-approvals-cli.ts:833
Agent review details

Security

None.

PR surface

Source +20, Tests +32. Total +52 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 27 7 +20
Tests 1 32 0 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 59 7 +52

Review metrics

Metric Value Why it matters
Production vs test delta production +20 net, tests +32 The new reusable terminal boundary needs to preserve existing table semantics across all six approval render paths.

Merge-risk options

Maintainer options:

  1. Preserve policy-table formatting (recommended)
    Revise the safety boundary so hostile stored values are sanitized without converting the Effective Policy table’s intentional line breaks into literal text.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Sanitize only untrusted approval-derived fields or add an explicit safe-cell boundary; preserve the Effective Policy multiline table layout and add a focused regression test.

Technical review

Best possible solution:

Sanitize approval-derived fields before rendering, or represent safe versus trusted cells explicitly, while retaining renderTable for the intentionally multiline Effective Policy layout.

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

Yes, from source: running the human Effective Policy path with a resolved policy produces cells containing intentional newlines, and the proposed sanitizer converts them to visible \n text.

Is this the best way to solve the issue?

No. The table-wide single-line sanitizer is too broad because it also transforms trusted layout; sanitizing untrusted approval-derived fields is the narrower compatible repair.

Full review comments:

  • [P2] Preserve the Effective Policy table’s intentional line breaks — src/cli/exec-approvals-cli.ts:833
    renderEffectivePolicy deliberately builds Requested, Host, and Effective with newline-separated fields, and renderTable has an explicit multiline-cell contract. Passing all cells through sanitizeTerminalText turns those separators into literal \n, flattening every human Effective Policy row. Sanitize untrusted approval fields before composition (or add an explicit safe-cell boundary) and cover this layout alongside the hostile-value regression.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5523f8a334c9.

Labels

Label changes:

  • add P2: This is a bounded operator-facing CLI correctness and terminal-safety repair with a concrete presentation regression to address before merge.
  • add merge-risk: 🚨 compatibility: The proposed renderer changes established human CLI output by flattening structured multiline policy cells.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its body nevertheless records a before/after terminal reproduction and JSON-preservation check.

Label justifications:

  • P2: This is a bounded operator-facing CLI correctness and terminal-safety repair with a concrete presentation regression to address before merge.
  • merge-risk: 🚨 compatibility: The proposed renderer changes established human CLI output by flattening structured multiline policy cells.
  • 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-authored PR is outside the external-contributor proof gate; its body nevertheless records a before/after terminal reproduction and JSON-preservation check.

Evidence

What I checked:

  • Current unsafe path: Current main sends all six exec-approval human tables to the ANSI-capable renderer, including Effective Policy and stored allowlist values. (src/cli/exec-approvals-cli.ts:830, 5523f8a334c9)
  • Introduced output regression: The proposed safe renderer sanitizes every table cell; Effective Policy deliberately creates multiline Requested, Host, and Effective cells, so its line breaks become visible literal escapes. (src/cli/exec-approvals-cli.ts:833, e890ca9b6e4e)
  • Existing renderer contract: The terminal-table test requires explicit cell newlines to render on adjacent table lines, confirming that multiline cells are intentional supported behavior. (packages/terminal-core/src/table.test.ts:453, 5523f8a334c9)
  • Existing safer caller pattern: The sibling exec-policy CLI sanitizes selected table values before retaining the standard table renderer, providing a narrower pattern for untrusted fields. (src/cli/exec-policy-cli.ts:123, 5523f8a334c9)
  • Current-main comparison: None of the PR’s three changed files or safe-text changed between the supplied base and current main, so current main does not already contain this fix. (src/cli/exec-approvals-cli.ts:537, 5523f8a334c9)
  • Feature provenance: History identifies the original approval-table rendering work and its write-path follow-up as authored by steipete; exact-line attribution remains incomplete because older promisor objects could not be retrieved locally. (src/cli/exec-approvals-cli.ts:830, f3554a3ad865)

Likely related people:

  • steipete: Authored the original approval-table commits and this PR; current shallow history also attributes the surrounding path to this area. (role: feature author and recent area contributor; confidence: high; commits: f3554a3ad865, 884211a924cf, e890ca9b6e4e; files: src/cli/exec-approvals-cli.ts, packages/terminal-core/src/table.ts)
  • Dallin Romney: Recent history includes a focused fix clarifying unstored exec-approval defaults on the same CLI surface. (role: recent adjacent contributor; confidence: medium; commits: ec391edea78d; files: src/cli/exec-approvals-cli.ts)
  • pick-cat: Recent terminal-core history covers C1 CSI, OSC, and sanitization behavior that this renderer boundary must preserve. (role: terminal-rendering contributor; confidence: medium; commits: 840f349d5d3f, fd5b121510be; files: packages/terminal-core/src/table.ts, packages/terminal-core/src/safe-text.ts)

Rank-up moves

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

  • Preserve the Effective Policy multiline layout while sanitizing untrusted fields.
  • Add a focused human-output regression for that layout, then let exact-head checks complete.

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.

@steipete
steipete merged commit 7c579ab into main Aug 14, 2026
239 checks passed
@steipete
steipete deleted the steipete/render-injection-sweep branch August 14, 2026 13:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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