Skip to content

Conversation

carllerche
Copy link
Member

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.

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 carllerche requested review from hawkw and a team as code owners August 29, 2025 19:00
@carllerche carllerche changed the title fmt: fix ANSI escape sequence injection vulnerability fmt: escape ANSI control characters Aug 29, 2025
@hawkw hawkw enabled auto-merge (squash) August 29, 2025 19:01
@hawkw hawkw merged commit 4c52ca5 into main Aug 29, 2025
55 of 56 checks passed
@hawkw hawkw deleted the escape-ansi branch August 29, 2025 19:08
@ziemkowski
Copy link

ziemkowski commented Sep 1, 2025

@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 colored-rs variables that are now escaped in my terminal. What's the proper way to preserve the formatting of those vars?

For example:

info!("This is red: {}", "color test".red());

now escapes the color sequence despite format().with_ansi(use_color):

This is red: \x1b[31mcolor test\x1b[0m

Thanks!

Edit: Looking at the PR, does this still accomplish what you're looking for if \x1b ESC is not escaped? It seems like it wants to escape the bad sequences, not disable escape sequences entirely, no?

Created followup issue: Regression: New tracing-subscriber breaks ANSI color and styling support

jo added a commit to jo/application-services that referenced this pull request Sep 2, 2025
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"
]
```
cfsmp3 pushed a commit to cfsmp3/monarch that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebookexperimental/reverie that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebookexperimental/rust-shed that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebook/pyrefly that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebookincubator/reindeer that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebook/sapling that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebookincubator/scrut that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to meta-pytorch/monarch that referenced this pull request Sep 5, 2025
…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
facebook-github-bot pushed a commit to facebookexperimental/hermit that referenced this pull request Sep 5, 2025
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
facebook-github-bot pushed a commit to facebook/hhvm that referenced this pull request Sep 5, 2025
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
anstylian added a commit to eigerco/axelar-relayer-core that referenced this pull request Sep 23, 2025
…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.
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.

3 participants