Skip to content
Merged
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
5 changes: 3 additions & 2 deletions crates/tinyinference-core/src/sanitize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ pub fn scrub_credentials(input: &str) -> String {
return full_match.to_string();
}
// Already redacted: an unquoted value stops at `*`, so a second pass
// would match the kept prefix and stack another marker. Leave it.
if rest.starts_with("*[REDACTED]") {
// would match the kept prefix and stack another marker. A short
// quoted value was replaced whole, so its value is the marker.
if rest.starts_with("*[REDACTED]") || value.as_str().starts_with("*[REDACTED]") {
return full_match.to_string();
}
// Replace only the value span. Rebuilding the key from captures used
Expand Down
9 changes: 9 additions & 0 deletions crates/tinyinference-core/src/sanitize_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ fn scrub_credentials_is_idempotent() {
assert_eq!(scrub_credentials(&once), once);
}

// A second pass must not stack a marker on a short value that the first
// pass replaced whole (`"ab"` -> `"*[REDACTED]"`).
#[test]
fn short_quoted_value_scrubs_idempotently() {
let once = scrub_credentials(r#"{"token":"ab"}"#);
assert_eq!(once, r#"{"token":"*[REDACTED]"}"#);
assert_eq!(scrub_credentials(&once), once);
}

#[test]
fn scrub_credentials_empty_input() {
assert_eq!(scrub_credentials(""), "");
Expand Down
Loading