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

feat(scrubbing): Scrub span.data.http.query with default scrubbers #1889

Merged
merged 7 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -8,6 +8,7 @@
- Protocol validation for source map image type. ([#1869](https://github.com/getsentry/relay/pull/1869))
- Strip quotes from client hint values. ([#1874](https://github.com/getsentry/relay/pull/1874))
- Add Dotnet, Javascript and PHP support for profiling. ([#1871](https://github.com/getsentry/relay/pull/1871), [#1876](https://github.com/getsentry/relay/pull/1876), [#1885](https://github.com/getsentry/relay/pull/1885))
- Scrub `span.data.http.query` with default scrubbers. ([#1889](https://github.com/getsentry/relay/pull/1889))

**Bug Fixes**:

Expand Down
57 changes: 54 additions & 3 deletions relay-general/src/pii/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,12 @@ fn insert_replacement_chunks(rule: &RuleRef, text: &str, output: &mut Vec<Chunk<

#[cfg(test)]
mod tests {
use crate::pii::{PiiConfig, ReplaceRedaction};

use crate::pii::{DataScrubbingConfig, PiiConfig, ReplaceRedaction};
use crate::processor::process_value;
use crate::protocol::{
Addr, DebugImage, DebugMeta, Event, ExtraValue, Headers, LogEntry, NativeDebugImage,
Request, TagEntry, Tags,
Addr, DataElement, DebugImage, DebugMeta, Event, ExtraValue, Headers, HttpElement,
LogEntry, NativeDebugImage, Request, Span, TagEntry, Tags,
};
use crate::testutils::assert_annotated_snapshot;
use crate::types::{Annotated, Object, Value};
Expand Down Expand Up @@ -967,4 +968,54 @@ mod tests {
);
assert_eq!(chunks, res);
}

#[test]
fn test_scrub_span_data_not_scrubbed() {
let mut span = Annotated::new(Span {
data: Annotated::new(DataElement {
http: Annotated::new(HttpElement {
query: Annotated::new("dance=true".to_owned()),
..Default::default()
}),
..Default::default()
}),
..Default::default()
});

let ds_config = DataScrubbingConfig {
scrub_data: true,
scrub_defaults: true,
..Default::default()
};
let pii_config = ds_config.pii_config().unwrap().as_ref().unwrap();
let mut pii_processor = PiiProcessor::new(pii_config.compiled());

process_value(&mut span, &mut pii_processor, ProcessingState::root()).unwrap();
assert_annotated_snapshot!(span);
}

#[test]
fn test_scrub_span_data_is_scrubbed() {
let mut span = Annotated::new(Span {
data: Annotated::new(DataElement {
http: Annotated::new(HttpElement {
query: Annotated::new("ccnumber=5105105105105100&process_id=123".to_owned()),
..Default::default()
}),
..Default::default()
}),
..Default::default()
});

let ds_config = DataScrubbingConfig {
scrub_data: true,
scrub_defaults: true,
..Default::default()
};
let pii_config = ds_config.pii_config().unwrap().as_ref().unwrap();
let mut pii_processor = PiiProcessor::new(pii_config.compiled());

process_value(&mut span, &mut pii_processor, ProcessingState::root()).unwrap();
assert_annotated_snapshot!(span);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: relay-general/src/pii/processor.rs
expression: span
---
{
"data": {
"http": {
"query": "ccnumber=[Filtered]&process_id=123"
}
},
"_meta": {
"data": {
"http": {
"query": {
"": {
"rem": [
[
"@creditcard:filter",
"s",
9,
19
]
],
"len": 40
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: relay-general/src/pii/processor.rs
expression: span
---
{
"data": {
"http": {
"query": "dance=true"
}
}
}
22 changes: 19 additions & 3 deletions relay-general/src/protocol/span.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::protocol::{JsonLenientString, OperationType, SpanId, SpanStatus, Timestamp, TraceId};
use crate::protocol::{
DataElement, JsonLenientString, OperationType, SpanId, SpanStatus, Timestamp, TraceId,
};
use crate::types::{Annotated, Object, Value};

#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
Expand Down Expand Up @@ -45,7 +47,7 @@ pub struct Span {

/// Arbitrary additional data on a span, like `extra` on the top-level event.
#[metastructure(pii = "maybe")]
pub data: Annotated<Object<Value>>,
pub data: Annotated<DataElement>,

// TODO remove retain when the api stabilizes
/// Additional arbitrary fields for forwards compatibility.
Expand All @@ -58,6 +60,8 @@ mod tests {
use chrono::{TimeZone, Utc};
use similar_asserts::assert_eq;

use crate::protocol::HttpElement;

use super::*;

#[test]
Expand All @@ -70,7 +74,12 @@ mod tests {
"op": "operation",
"span_id": "fa90fdead5f74052",
"trace_id": "4c79f60c11214eb38604f4ae0781bfb2",
"status": "ok"
"status": "ok",
"data": {
"http": {
"query": "is_sample_query=true"
}
}
iker-barriocanal marked this conversation as resolved.
Show resolved Hide resolved
}"#;

let span = Annotated::new(Span {
Expand All @@ -84,6 +93,13 @@ mod tests {
trace_id: Annotated::new(TraceId("4c79f60c11214eb38604f4ae0781bfb2".into())),
span_id: Annotated::new(SpanId("fa90fdead5f74052".into())),
status: Annotated::new(SpanStatus::Ok),
data: Annotated::new(DataElement {
http: Annotated::new(HttpElement {
query: Annotated::new("is_sample_query=true".to_owned()),
..Default::default()
}),
..Default::default()
}),
..Default::default()
});
assert_eq!(json, span.to_json_pretty().unwrap());
Expand Down
20 changes: 20 additions & 0 deletions relay-general/src/protocol/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,26 @@ impl schemars::JsonSchema for Timestamp {
}
}

#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct DataElement {
#[metastructure(pii = "maybe")]
pub http: Annotated<HttpElement>,

#[metastructure(additional_properties, retain = "true", pii = "maybe")]
pub other: Object<Value>,
}

#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct HttpElement {
#[metastructure(pii = "true")]
pub query: Annotated<String>,
Copy link
Member

Choose a reason for hiding this comment

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

span.data is documented as free-form, so when a user sends {"http": {"query": {"not": "a string"}}}, we should still accept it.

@iker-barriocanal could you check if the scrubbing still works when you change String to Value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! This is fixed in 03af9eb, and continues to work as expected.


#[metastructure(additional_properties, retain = "true", pii = "maybe")]
pub other: Object<Value>,
}

#[cfg(test)]
mod tests {
use similar_asserts::assert_eq;
Expand Down