-
Notifications
You must be signed in to change notification settings - Fork 93
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
feat(pii): Adopt new selectors #818
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f7f7832
feat(pii): Adopt new selectors
93fcd4d
Correct selectors and assertions
b2ecb0c
Use byte literals
971aec3
fix pii=maybe support in attachment scrubbing
untitaker 80eca59
remove outdated comment
untitaker a2e7173
Some tests for which selectors are specific
e96e9aa
change maybe to true
untitaker 3ce36c2
Make tests pass
bdadd5d
Add changelog
9ed08f4
Merge branch 'master' into feat/minidump-selectors
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,39 +256,61 @@ impl PiiAttachmentsProcessor<'_> { | |
let mut changed = false; | ||
|
||
for item in items { | ||
// IMPORTANT: Minidump sections are always classified as Pii:Maybe. This avoids to | ||
// accidentally scrub stack memory with highly generic selectors. TODO: Update the PII | ||
// system with a better approach. | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
|
||
match item { | ||
MinidumpItem::StackMemory(range) => { | ||
// IMPORTANT: The stack is PII::Maybe to avoid accidentally scrubbing it | ||
// with highly generic selectors. | ||
let slice = data | ||
.get_mut(range) | ||
.ok_or(ScrubMinidumpError::InvalidAddress)?; | ||
|
||
// Backwards-compatible visit | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
let state = | ||
file_state.enter_static("", Some(attrs), Some(ValueType::StackMemory)); | ||
changed |= self.scrub_bytes(slice, &state, ScrubEncodings::All); | ||
|
||
// Documented visit | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
let state = file_state.enter_static( | ||
"stack_memory", | ||
Some(attrs), | ||
Some(ValueType::Binary), | ||
); | ||
changed |= self.scrub_bytes(slice, &state, ScrubEncodings::All); | ||
} | ||
MinidumpItem::NonStackMemory(range) => { | ||
// Backwards-compatible visit. | ||
let slice = data | ||
.get_mut(range) | ||
.ok_or(ScrubMinidumpError::InvalidAddress)?; | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
let state = | ||
file_state.enter_static("", Some(attrs), Some(ValueType::HeapMemory)); | ||
changed |= self.scrub_bytes(slice, &state, ScrubEncodings::All); | ||
|
||
// Documented visit. | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
let state = file_state.enter_static( | ||
"heap_memory", | ||
Some(attrs), | ||
Some(ValueType::Binary), | ||
); | ||
changed |= self.scrub_bytes(slice, &state, ScrubEncodings::All); | ||
} | ||
MinidumpItem::LinuxEnviron(range) | MinidumpItem::LinuxCmdLine(range) => { | ||
let slice = data | ||
.get_mut(range) | ||
.ok_or(ScrubMinidumpError::InvalidAddress)?; | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
let state = file_state.enter_static("", Some(attrs), Some(ValueType::Binary)); | ||
changed |= self.scrub_bytes(slice, &state, ScrubEncodings::All); | ||
} | ||
MinidumpItem::CodeModuleName(range) => { | ||
let slice = data | ||
.get_mut(range) | ||
.ok_or(ScrubMinidumpError::InvalidAddress)?; | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
// Mirrors decisions made on NativeImagePath type | ||
let state = | ||
file_state.enter_static("code_file", Some(attrs), Some(ValueType::String)); | ||
|
@@ -299,6 +321,7 @@ impl PiiAttachmentsProcessor<'_> { | |
let slice = data | ||
.get_mut(range) | ||
.ok_or(ScrubMinidumpError::InvalidAddress)?; | ||
let attrs = Cow::Owned(FieldAttrs::new().pii(Pii::Maybe)); | ||
// Mirrors decisions made on NativeImagePath type | ||
let state = | ||
file_state.enter_static("debug_file", Some(attrs), Some(ValueType::String)); | ||
|
@@ -377,6 +400,33 @@ mod tests { | |
iter.next(); // remove main module | ||
iter.cloned().collect() | ||
} | ||
|
||
/// Returns the raw stack memory regions. | ||
fn stacks<'slf>(&'slf self, which: Which) -> Vec<&'slf [u8]> { | ||
let dump: &'slf Minidump<&'static [u8]> = match which { | ||
Which::Original => &self.orig_dump, | ||
Which::Scrubbed => &self.scrubbed_dump, | ||
}; | ||
|
||
let thread_list: MinidumpThreadList = dump.get_stream().unwrap(); | ||
let stack_rvas: Vec<RVA> = thread_list | ||
.threads | ||
.iter() | ||
.map(|t| t.raw.stack.memory.rva) | ||
.collect(); | ||
|
||
// These bytes are kept alive by our struct itself, so returning them with the | ||
// lifetime of our struct is fine. The lifetimes on the Minidump::MemoryRegions | ||
// iterator are currenty wrong and assumes we keep a reference to the | ||
// MinidumpMemoryList, hence we need to transmute this. See | ||
// https://github.com/luser/rust-minidump/pull/111 | ||
let mem_list: MinidumpMemoryList<'slf> = dump.get_stream().unwrap(); | ||
mem_list | ||
.iter() | ||
.filter(|mem| stack_rvas.contains(&mem.desc.memory.rva)) | ||
.map(|mem| unsafe { std::mem::transmute(mem.bytes) }) | ||
.collect() | ||
} | ||
} | ||
|
||
#[test] | ||
|
@@ -542,4 +592,149 @@ mod tests { | |
); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_backwards_compatible_selector() { | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$minidump.$stack_memory": ["@anything:mask"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This selector doesn't have to work, customers currently use |
||
} | ||
} | ||
), | ||
); | ||
for stack in scrubber.stacks(Which::Scrubbed) { | ||
assert!(stack.iter().all(|b| *b == b'*')); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_path_item_selector() { | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$minidump.stack_memory": ["@anything:mask"], | ||
} | ||
} | ||
), | ||
); | ||
for stack in scrubber.stacks(Which::Scrubbed) { | ||
assert!(stack.iter().all(|b| *b == b'*')); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_valuetype_selector() { | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$minidump.$binary": ["@anything:mask"], | ||
} | ||
} | ||
), | ||
); | ||
for stack in scrubber.stacks(Which::Scrubbed) { | ||
assert!(stack.iter().all(|b| *b == b'*')); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_valuetype_not_fully_qualified() { | ||
// Not fully qualified valuetype should not touch the stack | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$binary": ["@anything:mask"], | ||
} | ||
} | ||
), | ||
); | ||
for (scrubbed_stack, original_stack) in scrubber | ||
.stacks(Which::Scrubbed) | ||
.iter() | ||
.zip(scrubber.stacks(Which::Original).iter()) | ||
{ | ||
assert_eq!(scrubbed_stack, original_stack); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_wildcard() { | ||
// Wildcard should not touch the stack | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$minidump.*": ["@anything:mask"], | ||
} | ||
} | ||
), | ||
); | ||
for (scrubbed_stack, original_stack) in scrubber | ||
.stacks(Which::Scrubbed) | ||
.iter() | ||
.zip(scrubber.stacks(Which::Original).iter()) | ||
{ | ||
assert_eq!(scrubbed_stack, original_stack); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_deep_wildcard() { | ||
// Wildcard should not touch the stack | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$attachments.**": ["@anything:mask"], | ||
} | ||
} | ||
), | ||
); | ||
for (scrubbed_stack, original_stack) in scrubber | ||
.stacks(Which::Scrubbed) | ||
.iter() | ||
.zip(scrubber.stacks(Which::Original).iter()) | ||
{ | ||
assert_eq!(scrubbed_stack, original_stack); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_stack_scrubbing_binary_not_stack() { | ||
let scrubber = TestScrubber::new( | ||
"linux.dmp", | ||
include_bytes!("../../../tests/fixtures/linux.dmp"), | ||
serde_json::json!( | ||
{ | ||
"applications": { | ||
"$binary && !stack_memory": ["@anything:mask"], | ||
} | ||
} | ||
), | ||
); | ||
for (scrubbed_stack, original_stack) in scrubber | ||
.stacks(Which::Scrubbed) | ||
.iter() | ||
.zip(scrubber.stacks(Which::Original).iter()) | ||
{ | ||
assert_eq!(scrubbed_stack, original_stack); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to reinstantiate this I believe? Shouldn't you be able to pass down a Cow::Borrowed for the individual visits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't pass this to multiple calls and it also is not clonable. And since in the future we'll want some to be set to Pii::Yes de-duplicating this seems more cognitive overhead than it saves. That was the logic anyway, I don't feel strongly so could change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FieldAttrs is Copy