Skip to content

fix: sanitize picker labels/hints to prevent terminal escape injection#208

Draft
bukinoshita wants to merge 1 commit into
mainfrom
fix/sanitize-picker-terminal-escapes-eb4d
Draft

fix: sanitize picker labels/hints to prevent terminal escape injection#208
bukinoshita wants to merge 1 commit into
mainfrom
fix/sanitize-picker-terminal-escapes-eb4d

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

Summary by cubic

Sanitize picker option labels and hints to strip terminal escape sequences and control characters, preventing terminal escape injection in interactive CLI prompts. Centralized in pickId() to protect all PickerConfig flows; addresses BU-616.

  • Bug Fixes
    • Added sanitizeTerminalText utility using node:util’s stripVTControlCharacters and C0/C1 removal.
    • Applied sanitization to label/hint in pickId() before passing to @clack/prompts.
    • Added tests covering ANSI/OSC sequences, control bytes, and unicode.

Written for commit 9d8c423. Summary will update on new commits.

@bukinoshita
Copy link
Copy Markdown
Member Author

@cubic-dev-ai can you review?

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 9, 2026

@cubic-dev-ai can you review?

@bukinoshita I have started the AI code review. It will take a few minutes to complete.

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.

No issues found across 3 files

@bukinoshita
Copy link
Copy Markdown
Member Author

@cursor fix conflicts

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 13, 2026

The PR description was edited by cubic (the automated review tool) and the title is the same. I'll preserve those edits and not update the PR body/title since they're accurate. The conflicts are now resolved and the branch is pushed.

Resolved the merge conflicts by rebasing onto the latest main. The upstream had refactored pickId into pickItem + pickId and introduced an itemOptions intermediate step. I adapted the sanitization to work with this new structure — sanitizeTerminalText is now applied to the label and hint from itemOptions before they're passed to p.select(). All 95 test files (797 tests) pass, along with typecheck and lint.

Open in Web Open in Cursor 

Strip VT/ANSI/OSC control sequences and C0/C1 control characters from
picker option labels and hints in pickId() before passing them to
@clack/prompts. This prevents crafted resource names (e.g. email
subjects, template names, webhook endpoints) from injecting terminal
escape sequences that could manipulate an operator's terminal.

The fix is centralized in pickId() via a new sanitizeTerminalText
utility, protecting all current and future PickerConfig callers.

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
@cursor cursor Bot force-pushed the fix/sanitize-picker-terminal-escapes-eb4d branch from 0edc46a to 83b0a47 Compare April 13, 2026 22:28
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.

2 participants