Skip to content

Commit 729120c

Browse files
committed
docs: Address Weaponizing ANSI Escape Sequences
1 parent 8b81e46 commit 729120c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,35 @@
195195
//! Enabling test capturing comes at the expense of color and other style support
196196
//! and may have performance implications.
197197
//!
198-
//! ## Disabling colors
198+
//! ## Colors
199199
//!
200-
//! Colors and other styles can be configured with the `RUST_LOG_STYLE`
201-
//! environment variable. It accepts the following values:
200+
//! Outputting of colors and other styles can be controlled by the `RUST_LOG_STYLE`
201+
//! environment variable. It accepts the following [values][fmt::WriteStyle]:
202202
//!
203203
//! * `auto` (default) will attempt to print style characters, but don't force the issue.
204204
//! If the console isn't available on Windows, or if TERM=dumb, for example, then don't print colors.
205205
//! * `always` will always print style characters even if they aren't supported by the terminal.
206206
//! This includes emitting ANSI colors on Windows if the console API is unavailable.
207207
//! * `never` will never print style characters.
208208
//!
209+
//! Color may be applied in the logged message or a [custom formatter][fmt].
210+
//!
211+
//! <div class="warning">
212+
//!
213+
//! Logging of untrusted inputs can cause unexpected behavior as they may include ANSI escape codes which
214+
//! will be forwarded to the users terminal as part of "Weaponizing ANSI Escape Sequences".
215+
//!
216+
//! Mitigations include:
217+
//! - Setting `RUST_LOG_STYLE=never` to have all ANSI escape codes stripped
218+
//! - In the application, calling [`Builder::write_style(Never)`] to have all ANSI escape codes stripped
219+
//! - In the application, [stripping ANSI escape codes](https://docs.rs/anstream/latest/anstream/adapter/fn.strip_str.html)
220+
//! from user inputs
221+
//!
222+
//! Note: deactivating the build-time feature `color` is not a mitigation as that removes all ANSI escape code
223+
//! stripping from `env_logger`.
224+
//!
225+
//! </div>
226+
//!
209227
//! ## Tweaking the default format
210228
//!
211229
//! Parts of the default format can be excluded from the log output using the [`Builder`].

0 commit comments

Comments
 (0)