-
Notifications
You must be signed in to change notification settings - Fork 829
fmt: escape ANSI control characters #3368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes a security vulnerability where ANSI escape sequences in user input could be injected into terminal output, potentially allowing attackers to manipulate terminal behavior through log messages and error displays. The vulnerability occurred when user-controlled content was formatted using Display (`{}`) instead of Debug (`{:?}`) formatting, allowing raw ANSI sequences to pass through unescaped. Changes: - Add streaming ANSI escape wrapper to avoid string allocations - Escape message content in default and pretty formatters - Escape error Display content in all error formatting paths - Add comprehensive integration tests for all formatter types The fix specifically targets untrusted user input while preserving the ability for applications to deliberately include formatting in trusted contexts like thread names. Security impact: Prevents terminal injection attacks such as title bar manipulation, screen clearing, and other malicious terminal control sequences that could be injected through log messages.
@carllerche can you elaborate on "while preserving the ability for applications to deliberately include formatting in trusted contexts"? I have hundreds (thousands?) of traces with For example: info!("This is red: {}", "color test".red()); now escapes the color sequence despite
Thanks! Edit: Looking at the PR, does this still accomplish what you're looking for if Created followup issue: Regression: New tracing-subscriber breaks ANSI color and styling support |
Fixing the following error when integrating the code on desktop: ``` TEST-UNEXPECTED-ERROR | /builds/worker/checkouts/gecko/Cargo.lock:-1:-1 | Crate depends on a vulnerable version of tracing-subscriber. Advisory: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber ID: RUSTSEC-2025-0055 Report date: 2025-08-29 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR mozilla#3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. URL: GHSA-xwfj-jgwm-7wp5 Patched versions: [ ">=0.3.20" ] ```
Summary: ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Differential Revision: D81802144
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
…55) (#1114) Summary: Pull Request resolved: #1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
Summary: X-link: meta-pytorch/monarch#1114 ``` VULNERABILITY RUSTSEC-2025-0055 - 2025-08-29: Logging user input may result in poisoning logs with ANSI escape sequences Package: tracing-subscriber 0.3.19 Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input. ``` Reviewed By: dtolnay Differential Revision: D81802144 fbshipit-source-id: 1430805e74df708af6cb7580eb1b0a2a58b14ac2
…vulnerability Logs from cargo deny: error[vulnerability]: Logging user input may result in poisoning logs with ANSI escape sequences ┌─ /home/runner/work/axelar-relayer-core/axelar-relayer-core/Cargo.lock:330:1 │ 330 │ tracing-subscriber 0.3.19 registry+https://github.com/rust-lang/crates.io-index │ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ security vulnerability detected │ ├ ID: RUSTSEC-2025-0055 ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2025-0055 ├ Previous versions of tracing-subscriber were vulnerable to ANSI escape sequence injection attacks. Untrusted user input containing ANSI escape sequences could be injected into terminal output when logged, potentially allowing attackers to: - Manipulate terminal title bars - Clear screens or modify terminal display - Potentially mislead users through terminal manipulation In isolation, impact is minimal, however security issues have been found in terminal emulators that enabled an attacker to use ANSI escape sequences via logs to exploit vulnerabilities in the terminal emulator. This was patched in [PR #3368](tokio-rs/tracing#3368) to escape ANSI control characters from user input.
Fixes a security vulnerability where ANSI escape sequences in user input could be injected into terminal output, potentially allowing attackers to manipulate terminal behavior through log messages and error displays.
The vulnerability occurred when user-controlled content was formatted using Display (
{}
) instead of Debug ({:?}
) formatting, allowing raw ANSI sequences to pass through unescaped.Changes:
The fix specifically targets untrusted user input while preserving the ability for applications to deliberately include formatting in trusted contexts like thread names.
Security impact: Prevents terminal injection attacks such as title bar manipulation, screen clearing, and other malicious terminal control sequences that could be injected through log messages.