Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pii): Don't redact already redacted text [INGEST-109] #1177

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
**Bug Fixes**:

- Fix regression in CSP report parsing. ([#1174](https://github.com/getsentry/relay/pull/1174))
- Don't redact already redacted text. ([#1177](https://github.com/getsentry/relay/pull/1177))

## 22.1.0

Expand Down
37 changes: 35 additions & 2 deletions relay-general/src/pii/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,22 @@ fn apply_regex_to_chunks<'a>(
// on the chunks, but the `regex` crate does not support that.

let mut search_string = String::new();
let mut text_present = false;
for chunk in &chunks {
match chunk {
Chunk::Text { text } => search_string.push_str(&text.replace("\x00", "")),
Chunk::Text { text } => {
search_string.push_str(&text.replace("\x00", ""));
text_present = true;
}
Chunk::Redaction { .. } => search_string.push('\x00'),
}
}

// Early exit if there isn't any text to be redacted
if !text_present {
return chunks;
}

// Early exit if this regex does not match and return the original chunks.
let mut captures_iter = regex.captures_iter(&search_string).peekable();
if captures_iter.peek().is_none() {
Expand Down Expand Up @@ -356,7 +365,7 @@ fn insert_replacement_chunks(rule: &RuleRef, text: &str, output: &mut Vec<Chunk<

#[cfg(test)]
use {
crate::pii::PiiConfig,
crate::pii::{PiiConfig, ReplaceRedaction},
crate::processor::process_value,
crate::protocol::{
Addr, DebugImage, DebugMeta, Event, ExtraValue, Headers, LogEntry, NativeDebugImage,
Expand Down Expand Up @@ -945,3 +954,27 @@ fn test_ip_address_hashing_does_not_overwrite_id() {

assert_eq!(user.id.value().unwrap().as_str(), "123");
}

#[test]
fn test_replace_replaced_text() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It might be nice to have an additional test with an actual payload example (something like this):

fn test_authorization_scrubbing() {
let mut data = Event::from_value(
serde_json::json!({
"extra": {
"authorization": "foobar",
"auth": "foobar",
"auXth": "foobar",
}
})
.into(),
);
to prove that the issue is now fixed.

let chunks = vec![Chunk::Redaction {
text: "[Filtered]".into(),
rule_id: "@password:filter".into(),
ty: RemarkType::Substituted,
}];
let rule = RuleRef {
id: String::from("@password:filter"),
origin: String::from("@password:filter"),
ty: RuleType::Password,
redaction: Redaction::Replace(ReplaceRedaction {
text: String::from("[Filtered]"),
}),
};
let res = apply_regex_to_chunks(
chunks.clone(),
&rule,
&Regex::new(r#".*"#).unwrap(),
ReplaceBehavior::Value,
);
assert_eq!(chunks, res);
}