Skip to content

fix: sanitize untrusted terminal output to prevent escape sequence injection#240

Merged
felipefreitag merged 4 commits intomainfrom
fix/terminal-escape-injection-8ddb
Apr 13, 2026
Merged

fix: sanitize untrusted terminal output to prevent escape sequence injection#240
felipefreitag merged 4 commits intomainfrom
fix/terminal-escape-injection-8ddb

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

Summary by cubic

Sanitizes all untrusted interactive CLI output to block ANSI/OSC escape sequence injection (BU-650). Adds a shared safeTerminalText helper and applies it across webhooks, emails receiving, tables, and all interactive get commands.

  • Bug Fixes
    • Added safeTerminalText to strip ANSI/VT and dangerous control chars (keeps tabs/newlines).
    • Applied to: webhooks listen (type/resourceId/detail), table renderer (all cells), emails receiving listen, and all get commands.
    • JSON/pipe mode unchanged.

Written for commit 5f04f30. Summary will update on new commits.

…jection

Add safeTerminalText utility that strips ANSI/VT control sequences and
dangerous C0 control characters from untrusted data before rendering to
the terminal in interactive mode.

Applied to:
- webhooks listen: sanitize type, resourceId, and detail from webhook payloads
- table renderer: sanitize all cell contents in renderTable
- All get commands: sanitize API-returned fields in interactive output
- emails receiving listen: sanitize inbound email fields

JSON/pipe mode is unaffected since it uses JSON.stringify which escapes
control bytes.

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
@bukinoshita bukinoshita marked this pull request as ready for review April 13, 2026 16:40
@felipefreitag felipefreitag self-requested a review April 13, 2026 16:56
Copy link
Copy Markdown
Contributor

@felipefreitag felipefreitag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do a deep-sanitize instead of wrapping each field using runGet/runCreate/runList, I'll take a look

Instead of wrapping every field individually in each command, sanitize
the entire API response object once in runGet/runCreate/runList before
passing it to onInteractive. This removes per-field safeTerminalText
calls from 11 get commands and covers previously missed paths
(automations, events, renderDnsRecordsTable, status indicator defaults).

Also fixes regex literal lint warning and strips bare \r to prevent
terminal line-overwrite attacks.
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 14 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/commands/emails/receiving/get.ts">

<violation number="1">
P1: Untrusted email fields are written to interactive terminal output without sanitization, reintroducing escape-sequence injection risk.</violation>
</file>

<file name="src/commands/contact-properties/get.ts">

<violation number="1">
P1: Interactive CLI output logs untrusted API fields without `safeTerminalText`, reintroducing terminal escape-sequence injection risk.</violation>
</file>

<file name="src/commands/templates/get.ts">

<violation number="1">
P1: Interactive template fields are printed without `safeTerminalText`, reintroducing terminal escape-sequence injection risk.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

@felipefreitag felipefreitag merged commit db7a726 into main Apr 13, 2026
7 checks passed
@felipefreitag felipefreitag deleted the fix/terminal-escape-injection-8ddb branch April 13, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants