Skip to content

Strip control characters from the Command column (fixes #950) - #955

Open
MsfPablo wants to merge 2 commits into
dalance:masterfrom
MsfPablo:fix/command-escape-sequences
Open

Strip control characters from the Command column (fixes #950)#955
MsfPablo wants to merge 2 commits into
dalance:masterfrom
MsfPablo:fix/command-escape-sequences

Conversation

@MsfPablo

Copy link
Copy Markdown

Fixes #950.

Problem

Command::add only replaced \n and \t before display. A process's command line — including argv[0] — is fully controlled by whoever started it, and /proc/<pid>/cmdline is world-readable, so any local user can plant a process whose command line contains a raw ESC/CSI/OSC sequence. When another user runs procs, 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 final Command value 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_chars uses 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.

$ cargo test
test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

$ cargo fmt --check
(clean, no output)

$ cargo clippy --all-targets -- -D warnings
12 pre-existing errors, byte-identical to the `git stash` baseline on the
same commit (unsafe_op_in_unsafe_fn in the macOS paths, collapsible_if,
unnecessary_cast, etc.). No new lints introduced by this change.

Disclosure

This patch was written with AI assistance (Claude). I reviewed the diff and ran the verification commands above myself.

Pablo Garcia and others added 2 commits August 11, 2026 23:38
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
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.

Command column does not strip terminal escape sequences from process command lines, allowing injection via a crafted argv0

1 participant