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

Set ip_address to {{auto}} by default, even if sendDefaultPII is disabled #1665

Merged
merged 2 commits into from
Oct 9, 2023
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
- This will affect your callbacks, making this a breaking change.
- Load Device Contexts from Sentry Java ([#1616](https://github.com/getsentry/sentry-dart/pull/1616))
- Now the device context from Android is available in `BeforeSendCallback`

- Set ip_address to {{auto}} by default, even if sendDefaultPII is disabled ([#1665](https://github.com/getsentry/sentry-dart/pull/1665))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • 🚫 The changelog entry seems to be part of an already released section ## 8.0.0.
    Consider moving the entry to the ## Unreleased section, please.

- Instead use the "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io

## Unreleased

### Fixes
Expand Down
16 changes: 4 additions & 12 deletions dart/lib/src/sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import 'client_reports/discard_reason.dart';
import 'transport/data_category.dart';

/// Default value for [User.ipAddress]. It gets set when an event does not have
/// a user and IP address. Only applies if [SentryOptions.sendDefaultPii] is set
/// to true.
/// a user and IP address.
const _defaultIpAddress = '{{auto}}';

/// Logs crash reports and events to the Sentry.io service.
Expand Down Expand Up @@ -142,7 +141,7 @@ class SentryClient {
platform: event.platform ?? sdkPlatform(_options.platformChecker.isWeb),
);

event = _applyDefaultPii(event);
event = _createUserOrSetDefaultIpAddress(event);

if (event is SentryTransaction) {
return event;
Expand Down Expand Up @@ -222,20 +221,13 @@ class SentryClient {
return event;
}

/// This modifies the users IP address according
/// to [SentryOptions.sendDefaultPii].
SentryEvent _applyDefaultPii(SentryEvent event) {
if (!_options.sendDefaultPii) {
return event;
}
SentryEvent _createUserOrSetDefaultIpAddress(SentryEvent event) {
var user = event.user;
if (user == null) {
user = SentryUser(ipAddress: _defaultIpAddress);
return event.copyWith(user: user);
return event.copyWith(user: SentryUser(ipAddress: _defaultIpAddress));
} else if (event.user?.ipAddress == null) {
return event.copyWith(user: user.copyWith(ipAddress: _defaultIpAddress));
}

return event;
}

Expand Down
19 changes: 4 additions & 15 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -826,25 +826,14 @@ void main() {
});
});

group('SentryClient: apply default pii', () {
group('SentryClient: sets user & user ip', () {
late Fixture fixture;

setUp(() {
fixture = Fixture();
});

test('sendDefaultPii is disabled', () async {
final client = fixture.getSut(sendDefaultPii: false);

await client.captureEvent(fakeEvent);

final capturedEnvelope = fixture.transport.envelopes.first;
final capturedEvent = await eventFromEnvelope(capturedEnvelope);

expect(capturedEvent.user?.toJson(), fakeEvent.user?.toJson());
});

test('sendDefaultPii is enabled and event has no user', () async {
test('event has no user', () async {
final client = fixture.getSut(sendDefaultPii: true);
var fakeEvent = SentryEvent();

Expand All @@ -858,7 +847,7 @@ void main() {
expect(capturedEvent.user?.ipAddress, '{{auto}}');
});

test('sendDefaultPii is enabled and event has a user with IP address',
test('event has a user with IP address',
() async {
final client = fixture.getSut(sendDefaultPii: true);

Expand All @@ -875,7 +864,7 @@ void main() {
expect(capturedEvent.user?.email, fakeEvent.user!.email);
});

test('sendDefaultPii is enabled and event has a user without IP address',
test('event has a user without IP address',
() async {
final client = fixture.getSut(sendDefaultPii: true);

Expand Down
Loading