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): Mark sentry_user field as PII #3948

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 8 additions & 8 deletions relay-event-schema/src/protocol/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ pub struct User {
#[metastructure(pii = "true", max_chars = 128, skip_serialization = "empty")]
pub name: Annotated<String>,

/// The user string representation as handled in Sentry.
///
/// This field is computed by concatenating the name of specific fields of the `User`
/// struct with their value. For example, if `id` is set, `sentry_user` will be equal to
/// `"id:id-of-the-user".
#[metastructure(pii = "true", skip_serialization = "empty")]
Copy link
Member

Choose a reason for hiding this comment

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

mini nit: I would put this field declaration right after name, i.e. group it with the fields it is constructed from.

pub sentry_user: Annotated<String>,

/// Approximate geographical location of the end user or device.
#[metastructure(skip_serialization = "empty")]
pub geo: Annotated<Geo>,
Expand All @@ -76,14 +84,6 @@ pub struct User {
#[metastructure(skip_serialization = "empty")]
pub segment: Annotated<String>,

/// The user string representation as handled in Sentry.
///
/// This field is computed by concatenating the name of specific fields of the `User`
/// struct with their value. For example, if `id` is set, `sentry_user` will be equal to
/// `"id:id-of-the-user".
#[metastructure(skip_serialization = "empty")]
pub sentry_user: Annotated<String>,

/// Additional arbitrary fields, as stored in the database (and sometimes as sent by clients).
/// All data from `self.other` should end up here after store normalization.
#[metastructure(pii = "true", skip_serialization = "empty")]
Expand Down
27 changes: 27 additions & 0 deletions relay-pii/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,33 @@ mod tests {
assert_debug_snapshot!(&data);
}

#[test]
fn test_sentry_user() {
let mut data = Event::from_value(
json!({
"user": {
"ip_address": "73.133.27.120",
"sentry_user": "ip:73.133.27.120",
},
})
.into(),
);

let scrubbing_config = DataScrubbingConfig {
scrub_data: true,
scrub_ip_addresses: true,
scrub_defaults: true,
..Default::default()
};

let pii_config = to_pii_config(&scrubbing_config).unwrap();
let mut pii_processor = PiiProcessor::new(pii_config.compiled());

process_value(&mut data, &mut pii_processor, ProcessingState::root()).unwrap();

assert_debug_snapshot!(&data);
}

#[test]
fn test_basic_stripping() {
let config = serde_json::from_str::<PiiConfig>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
source: relay-pii/src/processor.rs
expression: "&data"
---
Event {
id: ~,
level: ~,
version: ~,
ty: ~,
fingerprint: ~,
culprit: ~,
transaction: ~,
transaction_info: ~,
time_spent: ~,
logentry: ~,
logger: ~,
modules: ~,
platform: ~,
timestamp: ~,
start_timestamp: ~,
received: ~,
server_name: ~,
release: ~,
dist: ~,
environment: ~,
site: ~,
user: User {
id: ~,
email: ~,
ip_address: Meta {
remarks: [
Remark {
ty: Substituted,
rule_id: "@ip:replace",
range: Some(
(
0,
4,
),
),
},
Remark {
ty: Removed,
rule_id: "@anything:remove",
range: None,
},
],
errors: [],
original_length: Some(
13,
),
original_value: None,
},
username: ~,
name: ~,
geo: ~,
segment: ~,
sentry_user: Annotated(
"ip:[ip]",
Meta {
remarks: [
Remark {
ty: Substituted,
rule_id: "@ip:replace",
range: Some(
(
3,
7,
),
),
},
],
errors: [],
original_length: Some(
16,
),
original_value: None,
},
),
data: ~,
other: {},
},
request: ~,
contexts: ~,
breadcrumbs: ~,
exceptions: ~,
stacktrace: ~,
template: ~,
threads: ~,
tags: ~,
extra: ~,
debug_meta: ~,
client_sdk: ~,
ingest_path: ~,
errors: ~,
key_id: ~,
project: ~,
grouping_config: ~,
checksum: ~,
csp: ~,
hpkp: ~,
expectct: ~,
expectstaple: ~,
spans: ~,
measurements: ~,
breakdowns: ~,
scraping_attempts: ~,
_metrics: ~,
_metrics_summary: ~,
_dsc: ~,
other: {},
}
Loading