Skip to content

fix(git): sanitize control characters in git output#1210

Merged
chaliy merged 1 commit intomainfrom
fix/1187-git-output-sanitization
Apr 11, 2026
Merged

fix(git): sanitize control characters in git output#1210
chaliy merged 1 commit intomainfrom
fix/1187-git-output-sanitization

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 11, 2026

Summary

  • Adds sanitize_git_output() function in git/mod.rs that strips ANSI escape sequences, null bytes, DEL, and C0/C1 control characters while preserving tab, newline, and carriage return
  • Applies sanitization to all git output paths: format_branch_list(), format_log(), format_status(), config_get(), grep(), rev_parse(), and show()
  • Adds 9 unit tests covering ANSI injection, null bytes, C0/C1 chars, DEL, Unicode preservation, and passthrough of normal text

Fixes #1187 (TM-GIT-015)

Test plan

  • cargo test -p bashkit --lib git::tests — all 9 sanitization tests pass
  • cargo test -p bashkit --features git — full test suite passes (95 passed)
  • cargo fmt --check — clean
  • cargo clippy -p bashkit --features git -- -D warnings — no new warnings (pre-existing dead code in curl.rs)

Strip ANSI escape sequences, null bytes, and C0/C1 control characters
from git output before it reaches interpreter stdout. Prevents terminal
injection via crafted repository metadata (branch names, commit messages,
config values, file paths).

Addresses TM-GIT-015. Closes #1187.
@chaliy chaliy merged commit dd35678 into main Apr 11, 2026
27 checks passed
@chaliy chaliy deleted the fix/1187-git-output-sanitization branch April 11, 2026 04:19
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.

sec(git): git config values not sanitized — potential injection via crafted repository metadata

1 participant