Skip to content

[WRONG BRANCH] fix(cli): neutralize terminal control characters in usage report - #330

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-cli-model-id-vulnerability
Draft

[WRONG BRANCH] fix(cli): neutralize terminal control characters in usage report#330
luvs01 wants to merge 1 commit into
mainfrom
codex/propose-fix-for-cli-model-id-vulnerability

Conversation

@luvs01

@luvs01 luvs01 commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The human ocx usage renderer printed provider and model identifiers verbatim, allowing logged control/OSC sequences to reach operator terminals and manipulate output (OSC 52, BEL, ESC, etc.).

Description

  • Add a terminalText sanitizer that replaces C0, DEL and C1 control characters with visible escape text (\x.. / \u....) to prevent terminal interpretation.\n- Apply the sanitizer to table headers/rows in table() and to scope/No usage recorded messages so attacker-controlled provider/model values are inert before printing.\n- Update formatUsageReport usage so all human-facing label cells are neutralized.\n- Add a focused regression test that injects ESC/OSC/BEL/newline into provider/model values and asserts the output contains escaped literals rather than control bytes.

Testing

  • bunx bun@1.4.0 test tests/cli-usage-report.test.ts — passed (13 tests).\n- bun run typecheck — passed.\n- bun run privacy:scan — passed.\n- git diff --check — passed.\n- Note: a repository-wide bun test run with the preinstalled Bun (older system binary) failed due to a runtime mismatch (zstdDecompressSync export), so a focused run using the repository-declared Bun (bunx bun@1.4.0) was used to validate the change successfully.

Codex Task

Summary by CodeRabbit

  • Bug Fixes
    • Terminal control characters in usage reports are now safely escaped and displayed as inert text.
    • Prevents unintended terminal formatting or control sequences in table headers, values, descriptions, and filter messages.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title fix(cli): neutralize terminal control characters in usage report [WRONG BRANCH] fix(cli): neutralize terminal control characters in usage report Aug 25, 2026
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6f53dbaf-5beb-4365-a8e2-bc42bbc04843

📥 Commits

Reviewing files that changed from the base of the PR and between 96e2f67 and 6a3c3e0.

📒 Files selected for processing (2)
  • src/cli/usage-report.ts
  • tests/cli-usage-report.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The usage report now escapes ASCII and extended control characters before rendering headers, cells, scope descriptions, and no-match filter descriptions. Tests verify that escape and bell characters appear as inert escaped text.

Changes

Usage report sanitization

Layer / File(s) Summary
Sanitize rendered report values
src/cli/usage-report.ts
Lines 45–53 add terminalText, which escapes ASCII control characters as \xNN and extended control characters as \uNNNN. Lines 70–71 sanitize table headers and cells before width calculation and rendering. Lines 82 and 92 sanitize scope and no-match filter descriptions.
Validate inert terminal output
tests/cli-usage-report.test.ts
Lines 65–77 verify that terminal escape and bell characters are absent from output while their escaped representations remain visible as plain text.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 6a3c3

The change makes provider and model identifiers inert in human usage reports by escaping terminal control characters, with focused tests and validation checks passing; no actionable merge-blocking risk remains beyond normal review.

Suggested reviewers: ingwannu, lidge-jun

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the main change: terminal control-character sanitization in the CLI usage report. The [WRONG BRANCH] prefix adds noise but does not make the title misleading.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/propose-fix-for-cli-model-id-vulnerability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions
github-actions Bot marked this pull request as draft August 25, 2026 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant