Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/issue-1605-redact-secrets-in-coloured-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Security
- Secrets in command output that contains terminal colour or cursor codes (for example `grep --color=always`) are now masked before the text reaches the AI, the chat or logs. The codes are removed from that text.
12 changes: 12 additions & 0 deletions crates/core/src/ai/live_redaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,16 @@ mod tests {
let all_but_last: String = (0..199).map(|i| format!("line {i}\n")).collect();
assert_eq!(shown, all_but_last);
}

#[test]
fn test_coloured_secret_across_chunks_is_never_shown_nor_half_escape() {
let raw = "ok\n\x1b[01;31m\x1b[Kpassword \x1b[m\x1b[K= hunter2\nnext\nmore\n";
assert_never_shows(raw, "hunter2");
for chunk in 1..=raw.len() {
let shown = live_view(raw, chunk);
assert!(!shown.contains('\u{1b}'), "chunk {chunk}: {shown:?}");
assert!(!shown.contains("[01;31m"), "chunk {chunk}: {shown:?}");
assert!(!shown.contains("[K"), "chunk {chunk}: {shown:?}");
}
}
}
1 change: 1 addition & 0 deletions crates/core/src/ai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod redactor_property;
mod redactor_reference;
mod rejection;
mod second_opinion;
mod terminal_escapes;
mod types;

#[cfg(test)]
Expand Down
9 changes: 3 additions & 6 deletions crates/core/src/ai/redactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,12 +1409,9 @@ impl OutputRedactor for DefaultOutputRedactor {
/// erkannt" dem Fail-safe-Prinzip (Spec 0002 Abschnitt 1) angemessener als
/// die Redaction bei Nicht-UTF-8-Output ganz zu überspringen.
fn redact_bytes(data: &[u8], patterns: &[PatternRule]) -> Vec<u8> {
let mut text = String::from_utf8_lossy(data).into_owned();
for rule in patterns {
if rule.regex.is_match(&text) {
text = rule.regex.replace_all(&text, rule.replacement).into_owned();
}
}
let rules = patterns.iter().map(|r| (&r.regex, r.replacement));
// Issue #1605: escape sequences are handled in `terminal_escapes`.
let text = super::terminal_escapes::redact_decoded(data, rules, REDACTED_PLACEHOLDER);
absorb_fragments_next_to_placeholders(&text).into_bytes()
}

Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/ai/redactor_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
//!
//! A failure means a redactor change redacts less than before. Fix the
//! redactor, not the reference.
//!
//! The generated documents contain no terminal escape sequences (issue
//! #1605), so the current redactor's escape stripping changes nothing here and
//! both sides see the same text; the reference is intentionally unchanged.

use proptest::prelude::*;

Expand Down
Loading
Loading