Strip control characters from the Command column (fixes #950) - #955
Open
MsfPablo wants to merge 2 commits into
Open
Strip control characters from the Command column (fixes #950)#955MsfPablo wants to merge 2 commits into
MsfPablo wants to merge 2 commits into
Conversation
Process command lines are attacker-controlled and world-readable, so a crafted argv0 containing raw ANSI escape sequences reached the terminal of anyone running procs unmodified. Replace all control characters with spaces, superseding the previous newline/tab-only replacement. Fixes dalance#950
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #950.
Problem
Command::addonly replaced\nand\tbefore display. A process's command line — including argv[0] — is fully controlled by whoever started it, and/proc/<pid>/cmdlineis world-readable, so any local user can plant a process whose command line contains a raw ESC/CSI/OSC sequence. When another user runsprocs, that sequence reaches their terminal unmodified.Fix
Adds
util::sanitize_control_chars, which replaces every control character (C0 including ESC 0x1B and BEL 0x07, DEL, and C1) with a space, and applies it to the finalCommandvalue on all four platform impls (Linux/Android, macOS, Windows, FreeBSD). This supersedes the old newline/tab replacement, which is now a subset of the same rule.Replacing rather than deleting keeps the surrounding text visible and the column width honest; the payload's remaining printable bytes (e.g.
]52;c;...) show up as inert text.Scope is deliberately limited to the Command column, as reported.
Test
util::tests::test_sanitize_control_charsuses the reporter's scenario — an OSC 52 clipboard-write sequence wrapping a base64 marker, plus embedded tab/newline — and asserts the output contains no control characters, that CSI sequences are neutralized, and that ordinary command lines pass through unchanged.Verification
Run on macOS.
Disclosure
This patch was written with AI assistance (Claude). I reviewed the diff and ran the verification commands above myself.