From 24f77a212ca077767d4053ed6737378683f5046c Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 3 Oct 2023 17:45:12 +0200 Subject: [PATCH 1/2] Create user and set ip address if missing --- dart/lib/src/sentry_client.dart | 16 ++++------------ dart/test/sentry_client_test.dart | 19 ++++--------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index d83207f1bd..d354e4a449 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -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. @@ -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; @@ -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; } diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index 15f91cdebe..522bfcae73 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -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(); @@ -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); @@ -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); From f36e28a34ec7f214cead21dbde635130cfa21632 Mon Sep 17 00:00:00 2001 From: Denis Andrasec Date: Tue, 3 Oct 2023 17:46:33 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee955dac28..323f9c563e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) + - Instead use the "Prevent Storing of IP Addresses" option in the "Security & Privacy" project settings on sentry.io + ## Unreleased ### Fixes