Skip to main content

par_term/session_logger/
mod.rs

1//! Session logging and recording for terminal sessions.
2//!
3//! This module provides automatic session logging with support for multiple formats:
4//! - Plain text: Simple output without escape sequences
5//! - HTML: Rendered output with colors preserved
6//! - Asciicast: asciinema-compatible format for replay/sharing
7//!
8//! # Security: Sensitive Data Filtering
9//!
10//! Session logs capture raw terminal I/O, which may include passwords and other
11//! credentials typed at prompts (sudo, ssh, gpg, etc.). To mitigate this risk,
12//! the logger supports **password prompt detection** via [`set_redact_passwords`]:
13//!
14//! When enabled, the logger monitors terminal output for common password prompt
15//! patterns. When a prompt is detected, subsequent keyboard input is replaced
16//! with `[INPUT REDACTED - echo off]` until the user presses Enter (completing
17//! the password entry). This is a heuristic approach and cannot guarantee
18//! detection of all sensitive input scenarios.
19//!
20//! Additionally, callers can explicitly signal that echo is suppressed (e.g.,
21//! because the PTY has disabled echo for a password prompt) by calling
22//! [`set_echo_suppressed`]. This provides a second layer of protection when
23//! terminal mode information is available.
24//!
25//! **WARNING**: Even with password redaction enabled, session logs may still
26//! contain sensitive data (API keys pasted into the terminal, tokens in command
27//! arguments, etc.). Users should treat session log files as potentially
28//! sensitive and store them accordingly.
29//!
30//! # Heuristic Redaction Limitations
31//!
32//! The password-prompt detection is **heuristic** and relies on a fixed list of known
33//! prompt strings (see `PASSWORD_PROMPT_PATTERNS` in `core`). It **cannot** guarantee
34//! that all sensitive input is redacted. Scenarios where credentials may still be
35//! captured include:
36//!
37//! - Custom or localised password prompts not in the pattern list
38//! - Credentials pasted into the terminal (no echo-suppress signal)
39//! - API keys or tokens typed as command arguments (e.g. `curl -H "Authorization: Bearer <token>"`)
40//! - Multi-factor authentication codes entered outside of recognised prompt patterns
41//! - Applications that suppress echo without emitting a matching prompt string
42//!
43//! **Recommendation**: If you regularly work with sensitive credentials in the terminal
44//! (vault access, production API keys, SSH passphrases, etc.), **disable session logging**
45//! for those sessions. Session logging can be toggled per-profile or globally via the
46//! par-term settings. Do not rely solely on redaction as a security control.
47//!
48//! [`set_redact_passwords`]: core::SessionLogger::set_redact_passwords
49//! [`set_echo_suppressed`]: core::SessionLogger::set_echo_suppressed
50
51pub mod core;
52pub(crate) mod format_writers;
53#[cfg(test)]
54mod tests;
55mod writers;
56
57pub use core::{SessionLogger, SharedSessionLogger, create_shared_logger};
58pub use writers::contains_password_prompt;