Skip to content

Strip control characters from externally sourced strings before TTY output#189

Merged
andrew merged 1 commit into
mainfrom
fix/terminal-escape-sanitize
May 2, 2026
Merged

Strip control characters from externally sourced strings before TTY output#189
andrew merged 1 commit into
mainfrom
fix/terminal-escape-sanitize

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 2, 2026

Changelog text fetched from upstream repositories, OSV `summary`/`details` fields, dependency names parsed from lockfiles, file content from `where`, and git commit author/message all reach the terminal with C0 control bytes intact. A hostile package author or commit author can embed ANSI/OSC escape sequences to clear the screen, move the cursor over earlier output, set the terminal title, inject OSC 8 hyperlinks, or write the clipboard on terminals that honour OSC 52.

Adds `Sanitize` in `cmd/output.go` which strips control characters other than `\t`/`\n` via `strings.Map` + `unicode.IsControl`, and applies it at the output sites in `changelog.go`, `vulns.go`, `diff_driver.go`, `where.go`, and `history.go`.

…utput

Changelog text fetched from upstream repos, OSV summary/details fields,
parsed dependency names from lockfiles, and git commit metadata all
reach the terminal with C0 control bytes intact, allowing ANSI/OSC
sequence injection (cursor movement, screen clearing, OSC 8 hyperlinks,
clipboard writes on terminals that honour OSC 52).

Adds a Sanitize helper in cmd/output.go that strips control characters
other than tab and newline, applied at each cited output site.
@andrew andrew merged commit a969d90 into main May 2, 2026
4 checks passed
@andrew andrew deleted the fix/terminal-escape-sanitize branch May 2, 2026 17:27
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.

1 participant