From 561d9f8205eda8272bf42f01747884569aa4c1cb Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 26 Nov 2026 12:09:53 +0100 Subject: [PATCH 1/4] ref(core)!: Remove sendDefaultPii Remove the deprecated option and use Data Collection defaults across SDK integrations. Document how to configure restrictive collection behavior when migrating to version 9. Fixes GH-6160 --- CHANGELOG.md | 4 + MIGRATION.md | 33 ++ REVIEWS.md | 4 +- .../android/core/ManifestMetadataReader.java | 5 - .../ApplicationExitInfoEventProcessorTest.kt | 17 +- .../core/DefaultAndroidEventProcessorTest.kt | 19 +- .../core/ManifestMetadataReaderTest.kt | 53 +-- .../src/main/AndroidManifest.xml | 5 - sentry-apollo-3/detekt-baseline.xml | 2 +- .../apollo3/SentryApollo3HttpInterceptor.kt | 66 +--- .../apollo3/SentryApollo3Interceptor.kt | 2 +- .../SentryApollo3InterceptorClientErrors.kt | 19 +- sentry-apollo-4/detekt-baseline.xml | 2 +- .../apollo4/SentryApollo4HttpInterceptor.kt | 66 +--- .../apollo4/SentryApollo4Interceptor.kt | 2 +- ...pollo4BuilderExtensionsClientErrorsTest.kt | 19 +- .../apollo5/SentryApollo5HttpInterceptor.kt | 65 +--- .../apollo5/SentryApollo5Interceptor.kt | 2 +- ...pollo5BuilderExtensionsClientErrorsTest.kt | 19 +- .../sentry/apollo/SentryApolloInterceptor.kt | 2 +- .../io/sentry/graphql/ExceptionReporter.java | 13 +- .../sentry/graphql/ExceptionReporterTest.kt | 32 +- .../ktorClient/SentryKtorClientUtils.kt | 54 +-- .../ktorClient/SentryKtorClientPluginTest.kt | 15 +- .../io/sentry/logback/SentryAppender.java | 9 +- .../io/sentry/logback/SentryAppenderTest.kt | 84 ++--- .../io/sentry/okhttp/SentryOkHttpUtils.kt | 63 +--- .../okhttp/SentryOkHttpEventListenerTest.kt | 2 - .../okhttp/SentryOkHttpInterceptorTest.kt | 8 +- .../io/sentry/okhttp/SentryOkHttpUtilsTest.kt | 35 +- .../OpenTelemetryAttributesExtractor.java | 30 +- .../java/io/sentry/samples/ktorClient/Main.kt | 1 - .../src/main/resources/application.properties | 1 - .../sentry/samples/spring7/SentryConfig.java | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/application.properties | 1 - .../samples/spring/jakarta/SentryConfig.java | 1 - .../sentry/samples/spring/SentryConfig.java | 1 - ...tryRequestHttpServletRequestProcessor.java | 21 +- ...yRequestHttpServletRequestProcessorTest.kt | 24 +- ...tryRequestHttpServletRequestProcessor.java | 21 +- ...yRequestHttpServletRequestProcessorTest.kt | 23 +- sentry-spring-7/api/sentry-spring-7.api | 1 - .../IntegrationTestApplication.kt | 2 +- .../java/io/sentry/spring7/EnableSentry.java | 7 - .../io/sentry/spring7/SentryHubRegistrar.java | 3 - .../sentry/spring7/SentryRequestResolver.java | 38 +- .../SentrySpanClientWebRequestFilter.java | 4 +- .../webflux/SentryRequestResolver.java | 42 +-- .../io/sentry/spring7/EnableSentryTest.kt | 21 +- ...ttpServletRequestSentryUserProviderTest.kt | 36 +- .../sentry/spring7/SentrySpringFilterTest.kt | 56 +-- .../io/sentry/spring7/SentryUserFilterTest.kt | 15 +- .../SpringSecuritySentryUserProviderTest.kt | 30 +- .../mvc/SentrySpringIntegrationTest.kt | 1 - .../boot4/SentryAutoConfigurationTest.kt | 10 +- .../boot4/it/SentrySpringIntegrationTest.kt | 1 - .../jakarta/SentryAutoConfigurationTest.kt | 10 +- .../jakarta/it/SentrySpringIntegrationTest.kt | 1 - .../boot/SentryAutoConfigurationTest.kt | 10 +- .../boot/it/SentrySpringIntegrationTest.kt | 1 - .../api/sentry-spring-jakarta.api | 1 - .../IntegrationTestApplication.kt | 2 +- .../sentry/spring/jakarta/EnableSentry.java | 7 - .../spring/jakarta/SentryHubRegistrar.java | 3 - .../spring/jakarta/SentryRequestResolver.java | 38 +- .../SentrySpanClientWebRequestFilter.java | 4 +- .../webflux/SentryRequestResolver.java | 42 +-- .../sentry/spring/jakarta/EnableSentryTest.kt | 21 +- ...ttpServletRequestSentryUserProviderTest.kt | 36 +- .../spring/jakarta/SentrySpringFilterTest.kt | 56 +-- .../spring/jakarta/SentryUserFilterTest.kt | 15 +- .../SpringSecuritySentryUserProviderTest.kt | 30 +- .../mvc/SentrySpringIntegrationTest.kt | 1 - sentry-spring/api/sentry-spring.api | 1 - .../IntegrationTestApplication.kt | 2 +- .../java/io/sentry/spring/EnableSentry.java | 7 - .../io/sentry/spring/SentryHubRegistrar.java | 3 - .../sentry/spring/SentryRequestResolver.java | 38 +- .../spring/webflux/SentryRequestResolver.java | 42 +-- .../io/sentry/spring/EnableSentryTest.kt | 21 +- ...ttpServletRequestSentryUserProviderTest.kt | 36 +- .../sentry/spring/SentrySpringFilterTest.kt | 63 +--- .../io/sentry/spring/SentryUserFilterTest.kt | 15 +- .../SpringSecuritySentryUserProviderTest.kt | 30 +- .../spring/mvc/SentrySpringIntegrationTest.kt | 1 - sentry/api/sentry.api | 12 - .../main/java/io/sentry/DataCollection.java | 10 +- .../io/sentry/DataCollectionResolver.java | 98 ++---- .../main/java/io/sentry/ExternalOptions.java | 10 - .../main/java/io/sentry/SentryOptions.java | 33 +- .../main/java/io/sentry/util/CookieUtils.java | 7 - .../java/io/sentry/util/GraphqlUtils.java | 4 +- .../main/java/io/sentry/util/HttpUtils.java | 19 - .../main/java/io/sentry/util/UrlUtils.java | 4 +- .../io/sentry/DataCollectionResolverTest.kt | 332 +++--------------- .../test/java/io/sentry/DataCollectionTest.kt | 11 +- .../java/io/sentry/ExternalOptionsTest.kt | 19 - .../java/io/sentry/MainEventProcessorTest.kt | 28 +- sentry/src/test/java/io/sentry/ScopesTest.kt | 95 +---- .../test/java/io/sentry/SentryOptionsTest.kt | 43 +-- .../test/java/io/sentry/SentryTracerTest.kt | 15 +- .../file/SentryFileInputStreamTest.kt | 30 +- .../file/SentryFileOutputStreamTest.kt | 32 +- .../file/SentryFileReaderTest.kt | 48 +-- .../file/SentryFileWriterTest.kt | 25 +- .../java/io/sentry/util/CookieUtilsTest.kt | 20 +- .../test/java/io/sentry/util/UrlUtilsTest.kt | 4 +- 121 files changed, 629 insertions(+), 1934 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ba9f2a168..29742d9ac0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ - Only the name and no-arg constructor of `SentryAndroidOptions` are kept, instead of every member of every `SentryOptions` subclass. - `sentry-android-ndk` no longer keeps native methods of all `io.sentry.**` classes. `sentry-native-ndk` still keeps its own. - If your code reaches any of these by name through JNI, reflection, or bindings, add your own keep rules for exactly what it uses. +- Remove the deprecated `sendDefaultPii` option from Java APIs, properties and environment variables, Android manifest metadata, and Spring annotations ([#6160](https://github.com/getsentry/sentry-java/issues/6160)) + - Configure automatically collected data with `dataCollection` instead. `DataCollection.forceDataCollection()` is also removed because the defaults now apply automatically. + - When no `dataCollection` setting is specified, user information, database query data, file paths, GraphQL documents and variables, and HTTP request and response bodies are enabled. Cookies, URL query parameters, and HTTP headers use their default deny lists. + - Logback raw message templates and parameters are controlled only by `includeUnencodedMessage` when an encoder is configured. - The Spring Boot 3 integrations are tested against Spring Boot 3.4 and newer. Spring Boot 3.2 and 3.3 are no longer supported ([#6656](https://github.com/getsentry/sentry-java/pull/6656)) - Remove the deprecated `io.sentry.android.core.LoadClass`. Use `io.sentry.util.LoadClass` instead ([#6594](https://github.com/getsentry/sentry-java/pull/6594)) - `SentryOptions.getIgnoredErrors()`, `getIgnoredTransactions()`, `getIgnoredCheckIns()` and `getIgnoredSpanOrigins()` now return `List` instead of `List`, matching their setters ([#6489](https://github.com/getsentry/sentry-java/pull/6489)) diff --git a/MIGRATION.md b/MIGRATION.md index 5513d143ddb..8ea23f3a3a4 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -1,3 +1,36 @@ +# Migrating from 8.x to 9.x + +## Replace `sendDefaultPii` with Data Collection + +Version 9 removes `sendDefaultPii` from the Java API, external configuration, Android manifest metadata, and Spring's `@EnableSentry` annotation. Configure each category through `dataCollection` instead. + +When no Data Collection setting is specified, the SDK now uses these defaults: + +- User information, database query data, file paths, GraphQL documents and variables, and HTTP request and response bodies are enabled. +- Cookies, URL query parameters, and HTTP request and response headers are collected with their default deny lists. + +Explicit settings still take precedence. If you relied on `sendDefaultPii=false` and want to disable these categories, configure them directly: + +```java +Sentry.init(options -> { + DataCollection dataCollection = options.getDataCollection(); + dataCollection.setUserInfo(false); + dataCollection.setDatabaseQueryData(false); + dataCollection.setFilePaths(false); + dataCollection.setCookies(KeyValueCollectionBehavior.off()); + dataCollection.setUrlQueryParams(KeyValueCollectionBehavior.off()); + dataCollection.setHttpBodies(java.util.Collections.emptySet()); + dataCollection.getHttpHeaders().setRequest(KeyValueCollectionBehavior.off()); + dataCollection.getHttpHeaders().setResponse(KeyValueCollectionBehavior.off()); + dataCollection.getGraphql().setDocument(false); + dataCollection.getGraphql().setVariables(false); +}); +``` + +`DataCollection.forceDataCollection()` is also removed because the documented defaults now apply automatically. + +For Logback, use `includeUnencodedMessage` to control whether events include the original message template and parameters when an encoder is configured. OpenTelemetry-derived HTTP headers now follow `dataCollection.httpHeaders.request`. + # Migrating from `sentry-java` to `sentry-android` #### Docs diff --git a/REVIEWS.md b/REVIEWS.md index 17cb3aefff6..42402317e12 100644 --- a/REVIEWS.md +++ b/REVIEWS.md @@ -48,8 +48,8 @@ rule file in [`.cursor/rules/`](.cursor/rules) for the area the diff touches (`a - Real secrets, tokens, or DSNs in code, logs, or configs. Obviously-fake DSNs in tests, samples, and docs are expected — do not flag those. - New code that collects user-identifiable data (headers, cookies, request/response bodies, URL - query strings, IPs, usernames, file paths, device identifiers) must be gated behind - `options.isSendDefaultPii()`, and must not be on by default otherwise. + query strings, IPs, usernames, file paths, device identifiers) must use the corresponding + `DataCollectionResolver` policy and follow the documented defaults. - Debug flags, verbose logging, or sampling overrides accidentally left enabled in production defaults. diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java b/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java index c24a2a8f6a9..ff24cf2b751 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ManifestMetadataReader.java @@ -115,8 +115,6 @@ final class ManifestMetadataReader { static final String COLLECT_ADDITIONAL_CONTEXT = "io.sentry.additional-context"; static final String COLLECT_EXTERNAL_STORAGE_CONTEXT = "io.sentry.external-storage-context"; - static final String SEND_DEFAULT_PII = "io.sentry.send-default-pii"; - static final String DATA_COLLECTION_USER_INFO = "io.sentry.data-collection.user-info"; static final String DATA_COLLECTION_HTTP_BODIES = "io.sentry.data-collection.http-bodies"; static final String DATA_COLLECTION_COOKIES = "io.sentry.data-collection.cookies"; @@ -564,9 +562,6 @@ static void applyMetadata( sdkInfo.setVersion(readStringNotNull(metadata, logger, SDK_VERSION, sdkInfo.getVersion())); options.setSdkVersion(sdkInfo); - options.setSendDefaultPii( - readBool(metadata, logger, SEND_DEFAULT_PII, options.isSendDefaultPii())); - // sdkInfo.addIntegration(); @Nullable diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt index 595e8bc28f1..f69da6caebe 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ApplicationExitInfoEventProcessorTest.kt @@ -106,11 +106,9 @@ class ApplicationExitInfoEventProcessorTest { populateScopeCache: Boolean = false, populateOptionsCache: Boolean = false, replayErrorSampleRate: Double? = null, - isSendDefaultPii: Boolean = true, ): ApplicationExitInfoEventProcessor { options.cacheDirPath = dir.newFolder().absolutePath options.environment = "release" - options.isSendDefaultPii = isSendDefaultPii options.addScopeObserver(PersistingScopeObserver(options)) whenever(buildInfo.sdkInfoVersion).thenReturn(currentSdk) @@ -248,7 +246,7 @@ class ApplicationExitInfoEventProcessorTest { fixture.options.dataCollection.setUserInfo(true) val hint = HintUtils.createWithTypeCheckHint(AbnormalExitHint()) - val processed = processEvent(hint, isSendDefaultPii = false) + val processed = processEvent(hint) assertNotNull(processed.contexts.device!!.id) } @@ -370,9 +368,10 @@ class ApplicationExitInfoEventProcessorTest { } @Test - fun `when backfillable event is enrichable, does not backfill user ip`() { + fun `when user info is disabled, does not backfill user ip`() { + fixture.options.dataCollection.setUserInfo(false) val hint = HintUtils.createWithTypeCheckHint(BackfillableHint()) - val processed = processEvent(hint, isSendDefaultPii = false, populateScopeCache = true) + val processed = processEvent(hint, populateScopeCache = true) assertNull(processed.user!!.ipAddress) } @@ -380,7 +379,7 @@ class ApplicationExitInfoEventProcessorTest { fun `when user info is disabled, does not backfill automatic user data`() { fixture.options.dataCollection.setUserInfo(false) val hint = HintUtils.createWithTypeCheckHint(BackfillableHint()) - val processed = processEvent(hint, isSendDefaultPii = true, populateScopeCache = true) + val processed = processEvent(hint, populateScopeCache = true) assertEquals("bot", processed.user!!.username) assertEquals("bot@me.com", processed.user!!.id) @@ -391,7 +390,7 @@ class ApplicationExitInfoEventProcessorTest { fun `when user info is enabled, backfills automatic user data`() { fixture.options.dataCollection.setUserInfo(true) val hint = HintUtils.createWithTypeCheckHint(BackfillableHint()) - val processed = processEvent(hint, isSendDefaultPii = false, populateScopeCache = true) + val processed = processEvent(hint, populateScopeCache = true) assertEquals("bot", processed.user!!.username) assertEquals("bot@me.com", processed.user!!.id) @@ -1214,7 +1213,6 @@ class ApplicationExitInfoEventProcessorTest { tmpDir, populateScopeCache = false, populateOptionsCache = false, - isSendDefaultPii = false, ) val hintTimestamp = System.currentTimeMillis() @@ -1271,7 +1269,6 @@ class ApplicationExitInfoEventProcessorTest { tmpDir, populateScopeCache = false, populateOptionsCache = false, - isSendDefaultPii = false, ) fixture.persistOptions(PROGUARD_UUID_FILENAME, "previous-uuid") setLastUpdateTime(2_000) @@ -1441,7 +1438,6 @@ class ApplicationExitInfoEventProcessorTest { hint: Hint, populateScopeCache: Boolean = false, populateOptionsCache: Boolean = false, - isSendDefaultPii: Boolean = true, configureEvent: SentryEvent.() -> Unit = {}, ): SentryEvent { val original = SentryEvent().apply(configureEvent) @@ -1451,7 +1447,6 @@ class ApplicationExitInfoEventProcessorTest { tmpDir, populateScopeCache = populateScopeCache, populateOptionsCache = populateOptionsCache, - isSendDefaultPii = isSendDefaultPii, ) return processor.process(original, hint)!! } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt index 3badbdbd853..648a121b060 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt @@ -73,8 +73,7 @@ class DefaultAndroidEventProcessorTest { lateinit var sentryTracer: SentryTracer - fun getSut(context: Context, isSendDefaultPii: Boolean = false): DefaultAndroidEventProcessor { - options.isSendDefaultPii = isSendDefaultPii + fun getSut(context: Context): DefaultAndroidEventProcessor { whenever(scopes.options).thenReturn(options) sentryTracer = SentryTracer(TransactionContext("", ""), scopes) return DefaultAndroidEventProcessor(context, buildInfo, options) @@ -269,16 +268,8 @@ class DefaultAndroidEventProcessorTest { } @Test - fun `when event user data does not have ip address set, sets no ip address if sendDefaultPii is false`() { - val sut = fixture.getSut(context, isSendDefaultPii = false) - val event = SentryEvent().apply { user = User() } - sut.process(event, Hint()) - assertNotNull(event.user) { assertNull(it.ipAddress) } - } - - @Test - fun `when event user data does not have ip address set, sets {{auto}} if sendDefaultPii is true`() { - val sut = fixture.getSut(context, isSendDefaultPii = true) + fun `when event user data does not have ip address set, sets {{auto}} by default`() { + val sut = fixture.getSut(context) val event = SentryEvent().apply { user = User() } sut.process(event, Hint()) assertNotNull(event.user) { assertEquals("{{auto}}", it.ipAddress) } @@ -287,7 +278,7 @@ class DefaultAndroidEventProcessorTest { @Test fun `when user info is disabled, sets installation id but not automatic ip`() { fixture.options.dataCollection.setUserInfo(false) - val sut = fixture.getSut(context, isSendDefaultPii = true) + val sut = fixture.getSut(context) val event = SentryEvent().apply { user = User() } sut.process(event, Hint()) @@ -301,7 +292,7 @@ class DefaultAndroidEventProcessorTest { @Test fun `when user info is enabled, sets automatic user data`() { fixture.options.dataCollection.setUserInfo(true) - val sut = fixture.getSut(context, isSendDefaultPii = false) + val sut = fixture.getSut(context) val event = SentryEvent().apply { user = User() } sut.process(event, Hint()) diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt index f5aa9596f31..8bc4fbf9f0f 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt @@ -1482,37 +1482,14 @@ class ManifestMetadataReaderTest { } @Test - fun `applyMetadata reads send default pii and keep default value if not found`() { - // Arrange - val context = fixture.getContext() - - // Act - ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - - // Assert - assertFalse(fixture.options.isSendDefaultPii) - } - - @Test - fun `applyMetadata reads send default pii to options`() { - // Arrange - val bundle = bundleOf(ManifestMetadataReader.SEND_DEFAULT_PII to true) - val context = fixture.getContext(metaData = bundle) - - // Act - ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - - // Assert - assertTrue(fixture.options.isSendDefaultPii) - } - - @Test - fun `applyMetadata preserves legacy data collection when metadata is absent`() { + fun `applyMetadata uses data collection defaults when metadata is absent`() { val context = fixture.getContext() ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - assertThat(fixture.options.dataCollectionResolver.isDataCollectionConfigured()).isFalse() + assertThat(fixture.options.dataCollectionResolver.isUserInfo).isTrue() + assertThat(fixture.options.dataCollectionResolver.cookies) + .isEqualTo(KeyValueCollectionBehavior.denyList()) } @Test @@ -1605,24 +1582,6 @@ class ManifestMetadataReaderTest { assertThat(fixture.options.dataCollection.httpBodies).isEmpty() } - @Test - fun `applyMetadata data collection takes precedence over send default pii`() { - val bundle = - bundleOf( - ManifestMetadataReader.SEND_DEFAULT_PII to false, - ManifestMetadataReader.DATA_COLLECTION_COOKIES + ".mode" to "off", - ) - val context = fixture.getContext(metaData = bundle) - - ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - - assertThat(fixture.options.isSendDefaultPii).isFalse() - assertThat(fixture.options.dataCollectionResolver.isDataCollectionConfigured()).isTrue() - assertThat(fixture.options.dataCollectionResolver.isUserInfo).isTrue() - assertThat(fixture.options.dataCollectionResolver.cookies) - .isEqualTo(KeyValueCollectionBehavior.off()) - } - @Test fun `applyMetadata ignores invalid data collection body type`() { val bundle = bundleOf(ManifestMetadataReader.DATA_COLLECTION_HTTP_BODIES to "invalid") @@ -1630,7 +1589,7 @@ class ManifestMetadataReaderTest { ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - assertThat(fixture.options.dataCollectionResolver.isDataCollectionConfigured()).isFalse() + assertThat(fixture.options.dataCollection.httpBodies).isNull() } @Test @@ -1640,7 +1599,7 @@ class ManifestMetadataReaderTest { ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - assertThat(fixture.options.dataCollectionResolver.isDataCollectionConfigured()).isFalse() + assertThat(fixture.options.dataCollection.cookies).isNull() } @Test diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/AndroidManifest.xml b/sentry-android-integration-tests/sentry-samples-android/src/main/AndroidManifest.xml index fd97e54ac5f..861d5b4e67f 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/AndroidManifest.xml +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/AndroidManifest.xml @@ -318,11 +318,6 @@ android:name="io.sentry.attach-view-hierarchy" android:value="true" /> - - - diff --git a/sentry-apollo-3/detekt-baseline.xml b/sentry-apollo-3/detekt-baseline.xml index 6bb8edffb36..dbe127496e0 100644 --- a/sentry-apollo-3/detekt-baseline.xml +++ b/sentry-apollo-3/detekt-baseline.xml @@ -7,7 +7,7 @@ CyclomaticComplexMethod:SentryApollo3HttpInterceptor.kt$SentryApollo3HttpInterceptor$private fun captureEvent( request: HttpRequest, response: HttpResponse, operationName: String?, operationType: String?, ) LongMethod:SentryApollo3HttpInterceptor.kt$SentryApollo3HttpInterceptor$private fun captureEvent( request: HttpRequest, response: HttpResponse, operationName: String?, operationType: String?, ) LongParameterList:SentryApollo3HttpInterceptor.kt$SentryApollo3HttpInterceptor$( span: ISpan?, request: HttpRequest, response: HttpResponse?, statusCode: Int?, operationName: String?, operationType: String?, operationId: String?, ) - LongParameterList:SentryApollo3InterceptorClientErrors.kt$SentryApollo3InterceptorClientErrors.Fixture$( captureFailedRequests: Boolean = DEFAULT_CAPTURE_FAILED_REQUESTS, failedRequestTargets: List<String> = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, sendDefaultPii: Boolean = false, includeCookies: Boolean = sendDefaultPii, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ) + LongParameterList:SentryApollo3InterceptorClientErrors.kt$SentryApollo3InterceptorClientErrors.Fixture$( captureFailedRequests: Boolean = DEFAULT_CAPTURE_FAILED_REQUESTS, failedRequestTargets: List<String> = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, includeCookies: Boolean = false, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ) MaxLineLength:LaunchDetailsQuery.kt$LaunchDetailsQuery.Companion$"query LaunchDetails(${'$'}id: ID!) { launch(id: ${'$'}id) { id site mission { name missionPatch(size: LARGE) } rocket { name type } } }" MaxLineLength:SentryApollo3InterceptorTest.kt$SentryApollo3InterceptorTest$"thirdPartyBaggage=someValue,secondThirdPartyBaggage=secondValue; property;propertyKey=propertyValue,anotherThirdPartyBaggage=anotherValue" MaxLineLength:SentryApollo3InterceptorTest.kt$SentryApollo3InterceptorTest.Fixture$"secondThirdPartyBaggage=secondValue; property;propertyKey=propertyValue,anotherThirdPartyBaggage=anotherValue" diff --git a/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt b/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt index 400643cef4a..5497738fae8 100644 --- a/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt +++ b/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3HttpInterceptor.kt @@ -181,7 +181,7 @@ constructor( operationId?.let { setData("operationId", it) } - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { variables?.let { setData("variables", it) } } setData(HTTP_METHOD_KEY, method.uppercase()) @@ -291,56 +291,28 @@ constructor( return STREAMING_MEDIA_TYPES.any { it.equals(mediaType, ignoreCase = true) } } - private fun getRequestHeaders(headers: List): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val requestHeaders = mutableMapOf() - for (header in headers) { - requestHeaders[header.name] = header.value - } - return HttpUtils.filterHeaders( - requestHeaders, - scopes.options.dataCollectionResolver.httpRequestHeaders, - ) - .toMutableMap() - } - return getHeaders(headers) - } - - private fun getResponseHeaders(headers: List): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val responseHeaders = mutableMapOf() - for (header in headers) { - responseHeaders[header.name] = header.value - } - return HttpUtils.filterHeaders( - responseHeaders, - scopes.options.dataCollectionResolver.httpResponseHeaders, - ) - .toMutableMap() + private fun getRequestHeaders(headers: List): MutableMap { + val requestHeaders = mutableMapOf() + for (header in headers) { + requestHeaders[header.name] = header.value } - return getHeaders(headers) + return HttpUtils.filterHeaders( + requestHeaders, + scopes.options.dataCollectionResolver.httpRequestHeaders, + ) + .toMutableMap() } - @Suppress("DEPRECATION") - private fun getHeaders(headers: List): MutableMap? { - // Headers are only sent if isSendDefaultPii is enabled due to PII - if (!scopes.options.isSendDefaultPii) { - return null + private fun getResponseHeaders(headers: List): MutableMap { + val responseHeaders = mutableMapOf() + for (header in headers) { + responseHeaders[header.name] = header.value } - - val headersMap = mutableMapOf() - - for (item in headers) { - val name = item.name - - // header is only sent if isn't sensitive - if (HttpUtils.containsSensitiveHeader(name)) { - continue - } - - headersMap[name] = item.value - } - return headersMap.ifEmpty { null } + return HttpUtils.filterHeaders( + responseHeaders, + scopes.options.dataCollectionResolver.httpResponseHeaders, + ) + .toMutableMap() } private fun captureEvent( diff --git a/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3Interceptor.kt b/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3Interceptor.kt index b58a2551566..ecceca12152 100644 --- a/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3Interceptor.kt +++ b/sentry-apollo-3/src/main/java/io/sentry/apollo3/SentryApollo3Interceptor.kt @@ -32,7 +32,7 @@ constructor(private val scopes: IScopes = ScopesAdapter.getInstance()) : ApolloI Base64.encodeToString(operationType(request).toByteArray(), Base64.NO_WRAP), ) - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { request.scalarAdapters?.let { builder.addHttpHeader( SENTRY_APOLLO_3_VARIABLES, diff --git a/sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorClientErrors.kt b/sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorClientErrors.kt index a450acbb96e..da31f355c9d 100644 --- a/sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorClientErrors.kt +++ b/sentry-apollo-3/src/test/java/io/sentry/apollo3/SentryApollo3InterceptorClientErrors.kt @@ -72,8 +72,7 @@ class SentryApollo3InterceptorClientErrors { failedRequestTargets: List = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, - sendDefaultPii: Boolean = false, - includeCookies: Boolean = sendDefaultPii, + includeCookies: Boolean = false, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ): ApolloClient { @@ -86,7 +85,6 @@ class SentryApollo3InterceptorClientErrors { SentryOptions().apply { dsn = "https://key@sentry.io/proj" sdkVersion = SdkVersion("test", "1.2.3") - isSendDefaultPii = sendDefaultPii configureOptions() }, ) @@ -265,7 +263,7 @@ class SentryApollo3InterceptorClientErrors { assertEquals(193L, request.bodySize) assertEquals(body, request.data) assertNull(request.cookies) - assertNull(request.headers) + assertNotNull(request.headers) }, any(), ) @@ -386,7 +384,6 @@ class SentryApollo3InterceptorClientErrors { val sut = fixture.getSut( responseBody = fixture.responseBodyNotOk, - sendDefaultPii = true, includeCookies = true, ) { dataCollection.cookies = KeyValueCollectionBehavior.off() @@ -419,8 +416,8 @@ class SentryApollo3InterceptorClientErrors { } @Test - fun `capture errors with more request context if sendDefaultPii is enabled`() { - val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true) + fun `capture errors with request cookies`() { + val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, includeCookies = true) executeQuery(sut) verify(fixture.scopes) @@ -428,7 +425,7 @@ class SentryApollo3InterceptorClientErrors { check { val request = it.request!! - assertEquals("theme=dark; sessionId=secret", request.cookies) + assertEquals("theme=dark; sessionId=[Filtered]", request.cookies) assertNotNull(request.headers) assertEquals("LaunchDetails", request.headers?.get("X-APOLLO-OPERATION-NAME")) }, @@ -450,7 +447,7 @@ class SentryApollo3InterceptorClientErrors { assertEquals(200, response.bodySize) assertEquals(fixture.responseBodyNotOk, response.data) assertNull(response.cookies) - assertNull(response.headers) + assertNotNull(response.headers) }, any(), ) @@ -509,8 +506,8 @@ class SentryApollo3InterceptorClientErrors { } @Test - fun `capture errors with more response context if sendDefaultPii is enabled`() { - val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true) + fun `capture errors with response cookies`() { + val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, includeCookies = true) executeQuery(sut) verify(fixture.scopes) diff --git a/sentry-apollo-4/detekt-baseline.xml b/sentry-apollo-4/detekt-baseline.xml index 371c726cb9f..a5d82730dbd 100644 --- a/sentry-apollo-4/detekt-baseline.xml +++ b/sentry-apollo-4/detekt-baseline.xml @@ -6,7 +6,7 @@ ClassNaming:LaunchDetailsQuery_VariablesAdapter.kt$LaunchDetailsQuery_VariablesAdapter : Adapter CyclomaticComplexMethod:SentryApollo4HttpInterceptor.kt$SentryApollo4HttpInterceptor$private fun captureEvent( request: HttpRequest, response: HttpResponse, operationName: String?, operationType: String?, ) LongMethod:SentryApollo4HttpInterceptor.kt$SentryApollo4HttpInterceptor$private fun captureEvent( request: HttpRequest, response: HttpResponse, operationName: String?, operationType: String?, ) - LongParameterList:SentryApollo4BuilderExtensionsClientErrorsTest.kt$SentryApollo4BuilderExtensionsClientErrorsTest.Fixture$( captureFailedRequests: Boolean = DEFAULT_CAPTURE_FAILED_REQUESTS, failedRequestTargets: List<String> = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, sendDefaultPii: Boolean = false, includeCookies: Boolean = sendDefaultPii, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ) + LongParameterList:SentryApollo4BuilderExtensionsClientErrorsTest.kt$SentryApollo4BuilderExtensionsClientErrorsTest.Fixture$( captureFailedRequests: Boolean = DEFAULT_CAPTURE_FAILED_REQUESTS, failedRequestTargets: List<String> = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, includeCookies: Boolean = false, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ) LongParameterList:SentryApollo4HttpInterceptor.kt$SentryApollo4HttpInterceptor$( span: ISpan?, request: HttpRequest, response: HttpResponse?, statusCode: Int?, operationName: String?, operationType: String?, operationId: String?, ) MaxLineLength:LaunchDetailsQuery.kt$LaunchDetailsQuery.Companion$"query LaunchDetails(${'$'}id: ID!) { launch(id: ${'$'}id) { id site mission { name missionPatch(size: LARGE) } rocket { name type } } }" MaxLineLength:LaunchDetailsQuerySelections.kt$LaunchDetailsQuerySelections$CompiledArgument.Builder(CompiledArgumentDefinition.Builder("size").build()).value("LARGE").build() diff --git a/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt b/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt index 539bdb25b21..b2128e8f54b 100644 --- a/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt +++ b/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4HttpInterceptor.kt @@ -180,7 +180,7 @@ constructor( operationId?.let { setData("operationId", it) } - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { variables?.let { setData("variables", it) } } setData(HTTP_METHOD_KEY, method.uppercase(Locale.ROOT)) @@ -290,56 +290,28 @@ constructor( return mediaType in STREAMING_MEDIA_TYPES } - private fun getRequestHeaders(headers: List): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val requestHeaders = mutableMapOf() - for (header in headers) { - requestHeaders[header.name] = header.value - } - return HttpUtils.filterHeaders( - requestHeaders, - scopes.options.dataCollectionResolver.httpRequestHeaders, - ) - .toMutableMap() - } - return getHeaders(headers) - } - - private fun getResponseHeaders(headers: List): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val responseHeaders = mutableMapOf() - for (header in headers) { - responseHeaders[header.name] = header.value - } - return HttpUtils.filterHeaders( - responseHeaders, - scopes.options.dataCollectionResolver.httpResponseHeaders, - ) - .toMutableMap() + private fun getRequestHeaders(headers: List): MutableMap { + val requestHeaders = mutableMapOf() + for (header in headers) { + requestHeaders[header.name] = header.value } - return getHeaders(headers) + return HttpUtils.filterHeaders( + requestHeaders, + scopes.options.dataCollectionResolver.httpRequestHeaders, + ) + .toMutableMap() } - @Suppress("DEPRECATION") - private fun getHeaders(headers: List): MutableMap? { - // Headers are only sent if isSendDefaultPii is enabled due to PII - if (!scopes.options.isSendDefaultPii) { - return null + private fun getResponseHeaders(headers: List): MutableMap { + val responseHeaders = mutableMapOf() + for (header in headers) { + responseHeaders[header.name] = header.value } - - val headersMap = mutableMapOf() - - for (item in headers) { - val name = item.name - - // header is only sent if isn't sensitive - if (HttpUtils.containsSensitiveHeader(name)) { - continue - } - - headersMap[name] = item.value - } - return headersMap.ifEmpty { null } + return HttpUtils.filterHeaders( + responseHeaders, + scopes.options.dataCollectionResolver.httpResponseHeaders, + ) + .toMutableMap() } private fun captureEvent( diff --git a/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4Interceptor.kt b/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4Interceptor.kt index 2481e2893d4..bf3ff21d7ca 100644 --- a/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4Interceptor.kt +++ b/sentry-apollo-4/src/main/java/io/sentry/apollo4/SentryApollo4Interceptor.kt @@ -35,7 +35,7 @@ constructor(@ApiStatus.Internal private val scopes: IScopes = ScopesAdapter.getI .addHttpHeader(OPERATION_NAME_HEADER_NAME, encodeHeaderValue(request.operation.name())) .addHttpHeader(OPERATION_TYPE_HEADER_NAME, encodeHeaderValue(operationType(request))) - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { request.scalarAdapters?.let { builder.addHttpHeader( VARIABLES_HEADER_NAME, diff --git a/sentry-apollo-4/src/test/java/io/sentry/apollo4/SentryApollo4BuilderExtensionsClientErrorsTest.kt b/sentry-apollo-4/src/test/java/io/sentry/apollo4/SentryApollo4BuilderExtensionsClientErrorsTest.kt index dfdf728708d..5acc1c96933 100644 --- a/sentry-apollo-4/src/test/java/io/sentry/apollo4/SentryApollo4BuilderExtensionsClientErrorsTest.kt +++ b/sentry-apollo-4/src/test/java/io/sentry/apollo4/SentryApollo4BuilderExtensionsClientErrorsTest.kt @@ -86,8 +86,7 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( failedRequestTargets: List = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, - sendDefaultPii: Boolean = false, - includeCookies: Boolean = sendDefaultPii, + includeCookies: Boolean = false, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ): ApolloClient { @@ -100,7 +99,6 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( SentryOptions().apply { dsn = "https://key@sentry.io/proj" sdkVersion = SdkVersion("test", "1.2.3") - isSendDefaultPii = sendDefaultPii configureOptions() }, ) @@ -279,7 +277,7 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( assertEquals(193L, request.bodySize) assertEquals(body, request.data) assertNull(request.cookies) - assertNull(request.headers) + assertNotNull(request.headers) }, any(), ) @@ -380,7 +378,6 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( val sut = fixture.getSut( responseBody = fixture.responseBodyNotOk, - sendDefaultPii = true, includeCookies = true, ) { dataCollection.cookies = KeyValueCollectionBehavior.off() @@ -430,8 +427,8 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( } @Test - fun `capture errors with more request context if sendDefaultPii is enabled`() { - val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true) + fun `capture errors with request cookies`() { + val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, includeCookies = true) executeQuery(sut) verify(fixture.scopes) @@ -439,7 +436,7 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( check { val request = it.request!! - assertEquals("theme=dark; sessionId=secret", request.cookies) + assertEquals("theme=dark; sessionId=[Filtered]", request.cookies) assertNotNull(request.headers) }, any(), @@ -460,7 +457,7 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( assertEquals(200, response.bodySize) assertEquals(fixture.responseBodyNotOk, response.data) assertNull(response.cookies) - assertNull(response.headers) + assertNotNull(response.headers) }, any(), ) @@ -519,8 +516,8 @@ abstract class SentryApollo4BuilderExtensionsClientErrorsTest( } @Test - fun `capture errors with more response context if sendDefaultPii is enabled`() { - val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true) + fun `capture errors with response cookies`() { + val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, includeCookies = true) executeQuery(sut) verify(fixture.scopes) diff --git a/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5HttpInterceptor.kt b/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5HttpInterceptor.kt index f273d438f34..c14ff0d4312 100644 --- a/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5HttpInterceptor.kt +++ b/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5HttpInterceptor.kt @@ -179,7 +179,7 @@ constructor( operationId?.let { setData("operationId", it) } - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { variables?.let { setData("variables", it) } } setData(HTTP_METHOD_KEY, method.uppercase(Locale.ROOT)) @@ -275,55 +275,28 @@ constructor( return mediaType in STREAMING_MEDIA_TYPES } - private fun getRequestHeaders(headers: List): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val requestHeaders = mutableMapOf() - for (header in headers) { - requestHeaders[header.name] = header.value - } - return HttpUtils.filterHeaders( - requestHeaders, - scopes.options.dataCollectionResolver.httpRequestHeaders, - ) - .toMutableMap() + private fun getRequestHeaders(headers: List): MutableMap { + val requestHeaders = mutableMapOf() + for (header in headers) { + requestHeaders[header.name] = header.value } - return getHeaders(headers) - } - - private fun getResponseHeaders(headers: List): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val responseHeaders = mutableMapOf() - for (header in headers) { - responseHeaders[header.name] = header.value - } - return HttpUtils.filterHeaders( - responseHeaders, - scopes.options.dataCollectionResolver.httpResponseHeaders, - ) - .toMutableMap() - } - return getHeaders(headers) + return HttpUtils.filterHeaders( + requestHeaders, + scopes.options.dataCollectionResolver.httpRequestHeaders, + ) + .toMutableMap() } - private fun getHeaders(headers: List): MutableMap? { - // Headers are only sent if isSendDefaultPii is enabled due to PII - if (!scopes.options.isSendDefaultPii) { - return null + private fun getResponseHeaders(headers: List): MutableMap { + val responseHeaders = mutableMapOf() + for (header in headers) { + responseHeaders[header.name] = header.value } - - val headersMap = mutableMapOf() - - for (item in headers) { - val name = item.name - - // header is only sent if isn't sensitive - if (HttpUtils.containsSensitiveHeader(name)) { - continue - } - - headersMap[name] = item.value - } - return headersMap.ifEmpty { null } + return HttpUtils.filterHeaders( + responseHeaders, + scopes.options.dataCollectionResolver.httpResponseHeaders, + ) + .toMutableMap() } private fun captureEvent( diff --git a/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5Interceptor.kt b/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5Interceptor.kt index cf6cdf31fda..2a7e4f07a16 100644 --- a/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5Interceptor.kt +++ b/sentry-apollo-5/src/main/java/io/sentry/apollo5/SentryApollo5Interceptor.kt @@ -28,7 +28,7 @@ constructor(@ApiStatus.Internal private val scopes: IScopes = ScopesAdapter.getI chain: ApolloInterceptorChain, ): Flow> { val variables = - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { request.scalarAdapters?.let { request.operation.variables(it).valueMap.toString() } } else { null diff --git a/sentry-apollo-5/src/test/java/io/sentry/apollo5/SentryApollo5BuilderExtensionsClientErrorsTest.kt b/sentry-apollo-5/src/test/java/io/sentry/apollo5/SentryApollo5BuilderExtensionsClientErrorsTest.kt index 82f8471d9e4..d8b7a9d85ce 100644 --- a/sentry-apollo-5/src/test/java/io/sentry/apollo5/SentryApollo5BuilderExtensionsClientErrorsTest.kt +++ b/sentry-apollo-5/src/test/java/io/sentry/apollo5/SentryApollo5BuilderExtensionsClientErrorsTest.kt @@ -83,8 +83,7 @@ abstract class SentryApollo5BuilderExtensionsClientErrorsTest( failedRequestTargets: List = listOf(DEFAULT_PROPAGATION_TARGETS), httpStatusCode: Int = 200, responseBody: String = responseBodyOk, - sendDefaultPii: Boolean = false, - includeCookies: Boolean = sendDefaultPii, + includeCookies: Boolean = false, socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, configureOptions: SentryOptions.() -> Unit = {}, ): ApolloClient { @@ -97,7 +96,6 @@ abstract class SentryApollo5BuilderExtensionsClientErrorsTest( SentryOptions().apply { dsn = "https://key@sentry.io/proj" sdkVersion = SdkVersion("test", "1.2.3") - isSendDefaultPii = sendDefaultPii configureOptions() }, ) @@ -279,15 +277,15 @@ abstract class SentryApollo5BuilderExtensionsClientErrorsTest( assertEquals(193L, request.bodySize) assertEquals(body, request.data) assertNull(request.cookies) - assertNull(request.headers) + assertNotNull(request.headers) }, any(), ) } @Test - fun `capture errors with more request context if sendDefaultPii is enabled`() { - val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true) + fun `capture errors with request cookies`() { + val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, includeCookies = true) executeQuery(sut) verify(fixture.scopes) @@ -295,7 +293,7 @@ abstract class SentryApollo5BuilderExtensionsClientErrorsTest( check { val request = it.request!! - assertEquals("theme=dark; sessionId=secret", request.cookies) + assertEquals("theme=dark; sessionId=[Filtered]", request.cookies) assertNotNull(request.headers) }, any(), @@ -393,7 +391,6 @@ abstract class SentryApollo5BuilderExtensionsClientErrorsTest( val sut = fixture.getSut( responseBody = fixture.responseBodyNotOk, - sendDefaultPii = true, includeCookies = true, ) { dataCollection.cookies = KeyValueCollectionBehavior.off() @@ -451,15 +448,15 @@ abstract class SentryApollo5BuilderExtensionsClientErrorsTest( assertEquals(200, response.bodySize) assertEquals(fixture.responseBodyNotOk, response.data) assertNull(response.cookies) - assertNull(response.headers) + assertNotNull(response.headers) }, any(), ) } @Test - fun `capture errors with more response context if sendDefaultPii is enabled`() { - val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, sendDefaultPii = true) + fun `capture errors with response cookies`() { + val sut = fixture.getSut(responseBody = fixture.responseBodyNotOk, includeCookies = true) executeQuery(sut) verify(fixture.scopes) diff --git a/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt b/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt index 9362d597615..803d7d29304 100644 --- a/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt +++ b/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt @@ -86,7 +86,7 @@ class SentryApolloInterceptor( val requestWithHeader = request.toBuilder().requestHeaders(headers).build() span.setData("operationId", requestWithHeader.operation.operationId()) - if (scopes.options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways) { + if (scopes.options.dataCollectionResolver.isGraphqlVariables) { span.setData("variables", requestWithHeader.operation.variables().valueMap().toString()) } diff --git a/sentry-graphql-core/src/main/java/io/sentry/graphql/ExceptionReporter.java b/sentry-graphql-core/src/main/java/io/sentry/graphql/ExceptionReporter.java index cae1eade220..f9e15f3136e 100644 --- a/sentry-graphql-core/src/main/java/io/sentry/graphql/ExceptionReporter.java +++ b/sentry-graphql-core/src/main/java/io/sentry/graphql/ExceptionReporter.java @@ -57,15 +57,12 @@ public void captureThrowable( private boolean isAllowedToAttachRequestBody(final @NotNull IScopes scopes) { final @NotNull SentryOptions options = scopes.getOptions(); - return options.getDataCollectionResolver().isGraphqlDocumentWithLegacyBodyGate() - || options.getDataCollectionResolver().isGraphqlVariablesWithLegacyBodyGate(); + return options.getDataCollectionResolver().isGraphqlDocument() + || options.getDataCollectionResolver().isGraphqlVariables(); } private boolean isAllowedToAttachResponseBody(final @NotNull IScopes scopes) { - return scopes - .getOptions() - .getDataCollectionResolver() - .isOutgoingResponseBodyWithLegacyBodyGate(); + return scopes.getOptions().getDataCollectionResolver().isOutgoingResponseBody(); } private void setRequestDetailsOnEvent( @@ -91,11 +88,11 @@ private void setDetailsOnRequest( final @NotNull Map data = new HashMap<>(); final @NotNull SentryOptions options = scopes.getOptions(); - if (options.getDataCollectionResolver().isGraphqlDocumentWithLegacyBodyGate()) { + if (options.getDataCollectionResolver().isGraphqlDocument()) { data.put("query", exceptionDetails.getQuery()); } - if (options.getDataCollectionResolver().isGraphqlVariablesWithLegacyBodyGate()) { + if (options.getDataCollectionResolver().isGraphqlVariables()) { final @Nullable Map variables = exceptionDetails.getVariables(); if (variables != null && !variables.isEmpty()) { data.put("variables", variables); diff --git a/sentry-graphql-core/src/test/kotlin/io/sentry/graphql/ExceptionReporterTest.kt b/sentry-graphql-core/src/test/kotlin/io/sentry/graphql/ExceptionReporterTest.kt index 0124c603834..32f808c8e46 100644 --- a/sentry-graphql-core/src/test/kotlin/io/sentry/graphql/ExceptionReporterTest.kt +++ b/sentry-graphql-core/src/test/kotlin/io/sentry/graphql/ExceptionReporterTest.kt @@ -38,10 +38,7 @@ import org.mockito.kotlin.whenever class ExceptionReporterTest { class Fixture { val defaultOptions = - SentryOptions().also { - it.isSendDefaultPii = true - it.maxRequestBodySize = SentryOptions.RequestSize.ALWAYS - } + SentryOptions().also { it.maxRequestBodySize = SentryOptions.RequestSize.ALWAYS } val exception = IllegalStateException("some exception") val scopes = mock() lateinit var instrumentationExecutionParameters: InstrumentationExecutionParameters @@ -199,9 +196,8 @@ class ExceptionReporterTest { } @Test - fun `does not attach query or variables if no max body size is set`() { - val exceptionReporter = - fixture.getSut(SentryOptions().also { it.isSendDefaultPii = true }, false) + fun `attaches query and variables by default regardless of max body size`() { + val exceptionReporter = fixture.getSut(SentryOptions()) exceptionReporter.captureThrowable( fixture.exception, ExceptionReporter.ExceptionDetails( @@ -221,7 +217,9 @@ class ExceptionReporterTest { assertEquals("GraphqlInstrumentation", ex.exceptionMechanism.type) assertNotNull(it.request) val request = it.request!! - assertNull(request.data) + val data = request.data as Map + assertEquals(fixture.query, data["query"]) + assertEquals(fixture.variables, data["variables"]) assertEquals("graphql", request.apiTarget) }, any(), @@ -260,7 +258,7 @@ class ExceptionReporterTest { } @Test - fun `legacy options can disable outgoing response data`() { + fun `legacy max request body option does not disable outgoing response data`() { val options = SentryOptions().also { it.maxRequestBodySize = SentryOptions.RequestSize.ALWAYS } val exceptionReporter = fixture.getSut(options) @@ -276,14 +274,14 @@ class ExceptionReporterTest { verify(fixture.scopes) .captureEvent( - org.mockito.kotlin.check { assertNull(it.contexts.response) }, + org.mockito.kotlin.check { assertNotNull(it.contexts.response?.data) }, any(), ) } @Test - fun `legacy request body size can disable outgoing response data`() { - val options = SentryOptions().also { it.isSendDefaultPii = true } + fun `default request body size does not disable outgoing response data`() { + val options = SentryOptions() val exceptionReporter = fixture.getSut(options) exceptionReporter.captureThrowable( @@ -298,7 +296,7 @@ class ExceptionReporterTest { verify(fixture.scopes) .captureEvent( - org.mockito.kotlin.check { assertNull(it.contexts.response) }, + org.mockito.kotlin.check { assertNotNull(it.contexts.response?.data) }, any(), ) } @@ -378,11 +376,13 @@ class ExceptionReporterTest { } @Test - fun `does not attach query or variables if sendDefaultPii is false`() { + fun `does not attach query or variables if data collection disables them`() { val exceptionReporter = fixture.getSut( - SentryOptions().also { it.maxRequestBodySize = SentryOptions.RequestSize.ALWAYS }, - false, + SentryOptions().also { + it.dataCollection.graphql.setDocument(false) + it.dataCollection.graphql.setVariables(false) + }, ) exceptionReporter.captureThrowable( fixture.exception, diff --git a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt index 4ab9310d6b1..0004e746bc7 100644 --- a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt +++ b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt @@ -67,46 +67,24 @@ internal object SentryKtorClientUtils { scopes.captureEvent(event, hint) } - private fun getRequestHeaders(scopes: IScopes, headers: Headers): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val requestHeaders = - headers.toMap().mapValues { (_, values) -> values.joinToString(",") }.toMutableMap() - return HttpUtils.filterHeaders( - requestHeaders, - scopes.options.dataCollectionResolver.httpRequestHeaders, - ) - .toMutableMap() - } - return getHeaders(scopes, headers) - } - - private fun getResponseHeaders(scopes: IScopes, headers: Headers): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val responseHeaders = - headers.toMap().mapValues { (_, values) -> values.joinToString(",") }.toMutableMap() - return HttpUtils.filterHeaders( - responseHeaders, - scopes.options.dataCollectionResolver.httpResponseHeaders, - ) - .toMutableMap() - } - return getHeaders(scopes, headers) + private fun getRequestHeaders(scopes: IScopes, headers: Headers): MutableMap { + val requestHeaders = + headers.toMap().mapValues { (_, values) -> values.joinToString(",") }.toMutableMap() + return HttpUtils.filterHeaders( + requestHeaders, + scopes.options.dataCollectionResolver.httpRequestHeaders, + ) + .toMutableMap() } - @Suppress("DEPRECATION") - private fun getHeaders(scopes: IScopes, headers: Headers): MutableMap? { - // Headers are only sent if isSendDefaultPii is enabled due to PII - if (!scopes.options.isSendDefaultPii) { - return null - } - - val res = mutableMapOf() - headers.toMap().forEach { (key, values) -> - if (!HttpUtils.containsSensitiveHeader(key)) { - res[key] = values.joinToString(",") - } - } - return res + private fun getResponseHeaders(scopes: IScopes, headers: Headers): MutableMap { + val responseHeaders = + headers.toMap().mapValues { (_, values) -> values.joinToString(",") }.toMutableMap() + return HttpUtils.filterHeaders( + responseHeaders, + scopes.options.dataCollectionResolver.httpResponseHeaders, + ) + .toMutableMap() } internal fun addBreadcrumb( diff --git a/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt b/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt index c508bc3a43a..ec5dad582e7 100644 --- a/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt +++ b/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt @@ -82,7 +82,6 @@ class SentryKtorClientPluginTest { listOf( HttpStatusCodeRange(HttpStatusCodeRange.DEFAULT_MIN, HttpStatusCodeRange.DEFAULT_MAX), ), - sendDefaultPii: Boolean = false, optionsConfiguration: Sentry.OptionsConfiguration? = null, httpClientEngine: HttpClientEngine = Java.create(), ): HttpClient { @@ -95,7 +94,6 @@ class SentryKtorClientPluginTest { } else if (!keepDefaultTracePropagationTargets) { it.setTracePropagationTargets(listOf("other-api")) } - it.isSendDefaultPii = sendDefaultPii } scope = Scope(options) whenever(scopes.options).thenReturn(options) @@ -205,7 +203,6 @@ class SentryKtorClientPluginTest { captureFailedRequests = true, httpStatusCode = statusCode, responseBody = responseBody, - sendDefaultPii = true, ) val requestBody = "test" @@ -328,7 +325,6 @@ class SentryKtorClientPluginTest { fixture.getSut( captureFailedRequests = true, httpStatusCode = 500, - sendDefaultPii = true, optionsConfiguration = Sentry.OptionsConfiguration { it.dataCollection.cookies = KeyValueCollectionBehavior.off() @@ -451,9 +447,8 @@ class SentryKtorClientPluginTest { } @Test - fun `does not capture headers when sendDefaultPii is disabled`(): Unit = runBlocking { - val sut = - fixture.getSut(captureFailedRequests = true, httpStatusCode = 500, sendDefaultPii = false) + fun `captures headers by default`(): Unit = runBlocking { + val sut = fixture.getSut(captureFailedRequests = true, httpStatusCode = 500) sut.get(fixture.server.url("/hello").toString()) { headers["myHeader"] = "myValue" } @@ -461,10 +456,10 @@ class SentryKtorClientPluginTest { .captureEvent( check { val sentryRequest = it.request!! - assertEquals(null, sentryRequest.headers) + assertEquals("myValue", sentryRequest.headers?.get("myHeader")) val sentryResponse = it.contexts.response!! - assertEquals(null, sentryResponse.headers) + assertNotNull(sentryResponse.headers) }, any(), ) @@ -591,7 +586,7 @@ class SentryKtorClientPluginTest { val httpClientSpan = fixture.sentryTracer.children.first() assertThat(httpClientSpan.description).isEqualTo("GET ${fixture.server.url("/hello")}") assertThat(httpClientSpan.data[SpanDataConvention.HTTP_QUERY_KEY]) - .isEqualTo("token=secret&page=1") + .isEqualTo("token=[Filtered]&page=1") assertThat(httpClientSpan.data[SpanDataConvention.HTTP_FRAGMENT_KEY]).isEqualTo("results") } diff --git a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java index 8c4fbe8ca23..20e641b8026 100644 --- a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java +++ b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java @@ -119,7 +119,7 @@ protected void append(@NotNull ILoggingEvent eventObject) { final Message message = new Message(); // Encoders may mask or strip PII. When one is configured, include the original message and - // parameters only if includeUnencodedMessage or the legacy sendDefaultPii option is enabled. + // parameters only if includeUnencodedMessage is enabled. if (shouldIncludeUnencodedMessage()) { message.setMessage(loggingEvent.getMessage()); message.setParams(toParams(loggingEvent.getArgumentArray())); @@ -179,7 +179,7 @@ protected void captureLog(@NotNull ILoggingEvent loggingEvent) { final @NotNull String formattedMessage = formatted(loggingEvent); // Encoders may mask or strip PII. When one is configured, include the original message and - // parameters only if includeUnencodedMessage or the legacy sendDefaultPii option is enabled. + // parameters only if includeUnencodedMessage is enabled. if (shouldIncludeUnencodedMessage()) { final @Nullable String nonFormattedMessage = loggingEvent.getMessage(); if (nonFormattedMessage != null && !formattedMessage.equals(nonFormattedMessage)) { @@ -202,11 +202,8 @@ protected void captureLog(@NotNull ILoggingEvent loggingEvent) { .log(sentryLevel, params, formattedMessage, arguments != null ? arguments : new Object[0]); } - @SuppressWarnings("deprecation") private boolean shouldIncludeUnencodedMessage() { - return encoder == null - || includeUnencodedMessage - || ScopesAdapter.getInstance().getOptions().isSendDefaultPii(); + return encoder == null || includeUnencodedMessage; } private String formatted(@NotNull ILoggingEvent loggingEvent) { diff --git a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt index 8147efa74c4..e08f0d5d93f 100644 --- a/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt +++ b/sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt @@ -56,7 +56,6 @@ class SentryAppenderTest { contextTags: List? = null, encoder: Encoder? = null, includeUnencodedMessage: Boolean = false, - sendDefaultPii: Boolean = false, logsEnabled: Boolean = false, options: SentryOptions = SentryOptions(), startLater: Boolean = false, @@ -73,7 +72,6 @@ class SentryAppenderTest { whenever(this.transportFactory.create(any(), any())).thenReturn(transport) this.encoder = encoder options.dsn = dsn - options.isSendDefaultPii = sendDefaultPii options.logs.loggerBatchProcessorFactory = ILoggerBatchProcessorFactory { options, client -> LoggerBatchProcessor(options, client, ImmediateExecutorService()) } @@ -171,7 +169,12 @@ class SentryAppenderTest { fun `encodes message`() { var encoder = PatternLayoutEncoder() encoder.pattern = "encoderadded %msg" - fixture = Fixture(minimumEventLevel = Level.DEBUG, encoder = encoder, sendDefaultPii = true) + fixture = + Fixture( + minimumEventLevel = Level.DEBUG, + encoder = encoder, + includeUnencodedMessage = true, + ) fixture.logger.info("testing encoding {}", "param1") verify(fixture.transport) @@ -189,10 +192,10 @@ class SentryAppenderTest { } @Test - fun `if encoder is set treats raw message and params as PII`() { + fun `if encoder is set omits raw message and params by default`() { var encoder = PatternLayoutEncoder() encoder.pattern = "encoderadded %msg" - fixture = Fixture(minimumEventLevel = Level.DEBUG, encoder = encoder, sendDefaultPii = false) + fixture = Fixture(minimumEventLevel = Level.DEBUG, encoder = encoder) fixture.logger.info("testing encoding {}", "param1") verify(fixture.transport) @@ -251,31 +254,6 @@ class SentryAppenderTest { ) } - @Test - fun `sendDefaultPii includes unencoded message when data collection is configured`() { - val encoder = PatternLayoutEncoder() - encoder.pattern = "encoded %msg" - val options = SentryOptions().apply { dataCollection.setFilePaths(false) } - fixture = - Fixture( - minimumEventLevel = Level.DEBUG, - encoder = encoder, - sendDefaultPii = true, - options = options, - ) - fixture.logger.info("testing encoding {}", "param1") - - verify(fixture.transport) - .send( - checkEvent { event -> - assertThat(event.message?.formatted).isEqualTo("encoded testing encoding param1") - assertThat(event.message?.message).isEqualTo("testing encoding {}") - assertThat(event.message?.params).containsExactly("param1") - }, - anyOrNull(), - ) - } - @Test fun `include unencoded message defaults to false and has no effect without encoder`() { fixture = Fixture(minimumEventLevel = Level.DEBUG, includeUnencodedMessage = true) @@ -313,7 +291,12 @@ class SentryAppenderTest { @Test fun `fallsback when encoder throws`() { var encoder = ThrowingEncoder() - fixture = Fixture(minimumEventLevel = Level.DEBUG, encoder = encoder, sendDefaultPii = true) + fixture = + Fixture( + minimumEventLevel = Level.DEBUG, + encoder = encoder, + includeUnencodedMessage = true, + ) fixture.logger.info("testing when encoder throws") verify(fixture.transport) @@ -538,7 +521,7 @@ class SentryAppenderTest { } @Test - fun `does not send formatted log message if encoder is available but sendDefaultPii is off`() { + fun `does not send template attributes if encoder is available by default`() { var encoder = PatternLayoutEncoder() encoder.pattern = "encoderadded %msg" fixture = Fixture(minimumLevel = Level.TRACE, logsEnabled = true, encoder = encoder) @@ -559,14 +542,14 @@ class SentryAppenderTest { } @Test - fun `sends formatted log message if encoder is available and sendDefaultPii is on but encoder throws`() { + fun `sends template attributes if encoder throws`() { var encoder = ThrowingEncoder() fixture = Fixture( minimumLevel = Level.TRACE, logsEnabled = true, - sendDefaultPii = true, encoder = encoder, + includeUnencodedMessage = true, ) fixture.logger.trace("Testing {} level", "TRACE") @@ -585,14 +568,14 @@ class SentryAppenderTest { } @Test - fun `sends formatted log message if encoder is available and sendDefaultPii is on`() { + fun `sends template attributes if unencoded message is included`() { var encoder = PatternLayoutEncoder() encoder.pattern = "encoderadded %msg" fixture = Fixture( minimumLevel = Level.TRACE, logsEnabled = true, - sendDefaultPii = true, + includeUnencodedMessage = true, encoder = encoder, ) fixture.logger.trace("Testing {} level", "TRACE") @@ -939,7 +922,7 @@ class SentryAppenderTest { } @Test - fun `does not set template or attributes on log with encoder when sendDefaultPii is false`() { + fun `does not set template or attributes on log with encoder by default`() { var encoder = PatternLayoutEncoder() encoder.pattern = "encoded %msg" fixture = @@ -947,7 +930,6 @@ class SentryAppenderTest { minimumLevel = Level.ERROR, logsEnabled = true, encoder = encoder, - sendDefaultPii = false, ) fixture.logger.error("testing message {}", "param") @@ -991,32 +973,6 @@ class SentryAppenderTest { ) } - @Test - fun `sets template and attributes on log with encoder when sendDefaultPii is true`() { - var encoder = PatternLayoutEncoder() - encoder.pattern = "encoded %msg" - fixture = - Fixture( - minimumLevel = Level.ERROR, - logsEnabled = true, - encoder = encoder, - sendDefaultPii = true, - ) - fixture.logger.error("testing message {}", "param") - - Sentry.flush(1000) - - verify(fixture.transport) - .send( - checkLogs { logs -> - val log = logs.items.first() - assertEquals("encoded testing message param", log.body) - assertEquals("testing message {}", log.attributes?.get("sentry.message.template")?.value) - assertEquals("param", log.attributes?.get("sentry.message.parameter.0")?.value) - }, - ) - } - @Test fun `sets properties from MDC as attributes on logs`() { fixture = diff --git a/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpUtils.kt b/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpUtils.kt index 106baced8ca..3b7bf57e380 100644 --- a/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpUtils.kt +++ b/sentry-okhttp/src/main/java/io/sentry/okhttp/SentryOkHttpUtils.kt @@ -69,59 +69,30 @@ internal object SentryOkHttpUtils { private fun getRequestHeaders( scopes: IScopes, requestHeaders: Headers, - ): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val headers = mutableMapOf() - for (i in 0 until requestHeaders.size) { - headers[requestHeaders.name(i)] = requestHeaders.value(i) - } - return HttpUtils.filterHeaders( - headers, - scopes.options.dataCollectionResolver.httpRequestHeaders, - ) - .toMutableMap() + ): MutableMap { + val headers = mutableMapOf() + for (i in 0 until requestHeaders.size) { + headers[requestHeaders.name(i)] = requestHeaders.value(i) } - return getHeaders(scopes, requestHeaders) + return HttpUtils.filterHeaders( + headers, + scopes.options.dataCollectionResolver.httpRequestHeaders, + ) + .toMutableMap() } private fun getResponseHeaders( scopes: IScopes, responseHeaders: Headers, - ): MutableMap? { - if (scopes.options.dataCollectionResolver.isDataCollectionConfigured) { - val headers = mutableMapOf() - for (i in 0 until responseHeaders.size) { - headers[responseHeaders.name(i)] = responseHeaders.value(i) - } - return HttpUtils.filterHeaders( - headers, - scopes.options.dataCollectionResolver.httpResponseHeaders, - ) - .toMutableMap() - } - return getHeaders(scopes, responseHeaders) - } - - @Suppress("DEPRECATION") - private fun getHeaders(scopes: IScopes, requestHeaders: Headers): MutableMap? { - // Headers are only sent if isSendDefaultPii is enabled due to PII - if (!scopes.options.isSendDefaultPii) { - return null - } - + ): MutableMap { val headers = mutableMapOf() - - for (i in 0 until requestHeaders.size) { - val name = requestHeaders.name(i) - - // header is only sent if isn't sensitive - if (HttpUtils.containsSensitiveHeader(name)) { - continue - } - - val value = requestHeaders.value(i) - headers[name] = value + for (i in 0 until responseHeaders.size) { + headers[responseHeaders.name(i)] = responseHeaders.value(i) } - return headers + return HttpUtils.filterHeaders( + headers, + scopes.options.dataCollectionResolver.httpResponseHeaders, + ) + .toMutableMap() } } diff --git a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt index 8ef0443381c..5d38f1322a4 100644 --- a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt +++ b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpEventListenerTest.kt @@ -53,7 +53,6 @@ class SentryOkHttpEventListenerTest { isSpanActive: Boolean = true, useInterceptor: Boolean = false, httpStatusCode: Int = 201, - sendDefaultPii: Boolean = false, configureOptions: (options: SentryOptions) -> Unit = {}, eventListener: EventListener? = null, eventListenerFactory: EventListener.Factory? = null, @@ -61,7 +60,6 @@ class SentryOkHttpEventListenerTest { options = SentryOptions().apply { dsn = "https://key@sentry.io/proj" - isSendDefaultPii = sendDefaultPii configureOptions(this) } whenever(scopes.options).thenReturn(options) diff --git a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpInterceptorTest.kt b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpInterceptorTest.kt index 8e4d492692a..fd30fa2eaef 100644 --- a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpInterceptorTest.kt +++ b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpInterceptorTest.kt @@ -88,7 +88,6 @@ class SentryOkHttpInterceptorTest { listOf( HttpStatusCodeRange(HttpStatusCodeRange.DEFAULT_MIN, HttpStatusCodeRange.DEFAULT_MAX), ), - sendDefaultPii: Boolean = false, eventListener: EventListener? = null, additionalInterceptors: List = emptyList(), isReplayRecording: Boolean = true, @@ -104,7 +103,6 @@ class SentryOkHttpInterceptorTest { } else if (!keepDefaultTracePropagationTargets) { it.setTracePropagationTargets(listOf("other-api")) } - it.isSendDefaultPii = sendDefaultPii } scope = Scope(options) whenever(scopes.options).thenReturn(options) @@ -661,7 +659,6 @@ class SentryOkHttpInterceptorTest { captureFailedRequests = true, httpStatusCode = statusCode, responseBody = "fail", - sendDefaultPii = true, ) val request = getRequest(url = "/hello?myQuery=myValue#myFragment") @@ -676,7 +673,6 @@ class SentryOkHttpInterceptorTest { assertEquals("myFragment", sentryRequest.fragment) assertEquals("GET", sentryRequest.method) - // because of isSendDefaultPii assertNotNull(sentryRequest.headers) assertNull(sentryRequest.cookies) @@ -684,7 +680,6 @@ class SentryOkHttpInterceptorTest { assertEquals(statusCode, sentryResponse.statusCode) assertEquals(response.body!!.contentLength(), sentryResponse.bodySize) - // because of isSendDefaultPii assertNotNull(sentryResponse.headers) assertNull(sentryResponse.cookies) @@ -734,8 +729,7 @@ class SentryOkHttpInterceptorTest { @Test fun `captures an error event with headers`() { - val sut = - fixture.getSut(captureFailedRequests = true, httpStatusCode = 500, sendDefaultPii = true) + val sut = fixture.getSut(captureFailedRequests = true, httpStatusCode = 500) sut.newCall(getRequest()).execute() diff --git a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpUtilsTest.kt b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpUtilsTest.kt index b89a1f5bf5c..ca8552ca67d 100644 --- a/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpUtilsTest.kt +++ b/sentry-okhttp/src/test/java/io/sentry/okhttp/SentryOkHttpUtilsTest.kt @@ -36,14 +36,12 @@ class SentryOkHttpUtilsTest { httpStatusCode: Int = 500, responseBody: String = "success", socketPolicy: SocketPolicy = SocketPolicy.KEEP_OPEN, - sendDefaultPii: Boolean = false, configureOptions: SentryOptions.() -> Unit = {}, ): OkHttpClient { val options = SentryOptions().apply { dsn = "https://key@sentry.io/proj" setTracePropagationTargets(listOf(server.hostName)) - isSendDefaultPii = sendDefaultPii configureOptions() } whenever(scopes.options).thenReturn(options) @@ -100,8 +98,8 @@ class SentryOkHttpUtilsTest { } @Test - fun `captureClientError with sendDefaultPii sends headers`() { - val sut = fixture.getSut(sendDefaultPii = true) + fun `captureClientError sends headers and cookies by default`() { + val sut = fixture.getSut() val request = getRequest() val response = sut.newCall(request).execute() @@ -163,8 +161,8 @@ class SentryOkHttpUtilsTest { } @Test - fun `data collection cookie defaults ignore sendDefaultPii`() { - val sut = fixture.getSut(sendDefaultPii = false) { dataCollection.setUserInfo(false) } + fun `data collection uses cookie defaults`() { + val sut = fixture.getSut() val request = getRequest() val response = sut.newCall(request).execute() @@ -247,29 +245,4 @@ class SentryOkHttpUtilsTest { verify(fixture.scopes) .captureEvent(check { assertTrue(it.contexts.response!!.headers!!.isEmpty()) }, any()) } - - @Test - fun `captureClientError without sendDefaultPii does not send headers`() { - val sut = fixture.getSut(sendDefaultPii = false) - val request = getRequest() - val response = sut.newCall(request).execute() - - SentryOkHttpUtils.captureClientError(fixture.scopes, request, response) - verify(fixture.scopes) - .captureEvent( - check { - val req = it.request - val resp = it.contexts.response - - assertIs(req) - assertNull(req.headers) - assertNull(req.cookies) - - assertIs(resp) - assertNull(resp.headers) - assertNull(resp.cookies) - }, - any(), - ) - } } diff --git a/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryAttributesExtractor.java b/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryAttributesExtractor.java index 5ae9de98cc6..7ff051d32d2 100644 --- a/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryAttributesExtractor.java +++ b/sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OpenTelemetryAttributesExtractor.java @@ -74,33 +74,29 @@ private void addRequestAttributesToScope( } } - @SuppressWarnings({"deprecation", "unchecked"}) + @SuppressWarnings("unchecked") private static Map collectHeaders( final @NotNull Attributes attributes, final @NotNull SentryOptions options) { - Map headers = new HashMap<>(); + final Map headers = new HashMap<>(); attributes.forEach((key, value) -> { final @NotNull String attributeKeyAsString = key.getKey(); - if (attributeKeyAsString.startsWith(HTTP_REQUEST_HEADER_PREFIX)) { + if (attributeKeyAsString.startsWith(HTTP_REQUEST_HEADER_PREFIX) && value instanceof List) { final @NotNull String headerName = StringUtils.removePrefix(attributeKeyAsString, HTTP_REQUEST_HEADER_PREFIX); - if (options.isSendDefaultPii() || !HttpUtils.containsSensitiveHeader(headerName)) { - if (value instanceof List) { - try { - final @NotNull List headerValues = (List) value; - headers.put( - headerName, - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - headerValues, headerName, null))); - } catch (Throwable t) { - options.getLogger().log(SentryLevel.WARNING, "Expected a List as header", t); - } - } + try { + final @NotNull List headerValues = (List) value; + headers.put( + headerName, + toString( + CookieUtils.filterOutSecurityCookiesFromHeader(headerValues, headerName, null))); + } catch (Throwable t) { + options.getLogger().log(SentryLevel.WARNING, "Expected a List as header", t); } } }); - return headers; + return HttpUtils.filterHeaders( + headers, options.getDataCollectionResolver().getHttpRequestHeaders()); } public @Nullable String extractUrl( diff --git a/sentry-samples/sentry-samples-ktor-client/src/main/java/io/sentry/samples/ktorClient/Main.kt b/sentry-samples/sentry-samples-ktor-client/src/main/java/io/sentry/samples/ktorClient/Main.kt index 38ae2506ce7..90090f0c6ff 100644 --- a/sentry-samples/sentry-samples-ktor-client/src/main/java/io/sentry/samples/ktorClient/Main.kt +++ b/sentry-samples/sentry-samples-ktor-client/src/main/java/io/sentry/samples/ktorClient/Main.kt @@ -13,7 +13,6 @@ fun main() { Sentry.init { options -> options.dsn = "https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563" options.isDebug = true - options.isSendDefaultPii = true options.tracesSampleRate = 1.0 options.addInAppInclude("io.sentry.samples") options.isGlobalHubMode = true diff --git a/sentry-samples/sentry-samples-netflix-dgs/src/main/resources/application.properties b/sentry-samples/sentry-samples-netflix-dgs/src/main/resources/application.properties index 199ae97c2d3..513bc01a9ba 100644 --- a/sentry-samples/sentry-samples-netflix-dgs/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-netflix-dgs/src/main/resources/application.properties @@ -4,4 +4,3 @@ sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/542 sentry.max-request-body-size=medium sentry.traces-sample-rate=1.0 sentry.debug=true -sentry.send-default-pii=true diff --git a/sentry-samples/sentry-samples-spring-7/src/main/java/io/sentry/samples/spring7/SentryConfig.java b/sentry-samples/sentry-samples-spring-7/src/main/java/io/sentry/samples/spring7/SentryConfig.java index ef327a48758..7a29d329c3c 100644 --- a/sentry-samples/sentry-samples-spring-7/src/main/java/io/sentry/samples/spring7/SentryConfig.java +++ b/sentry-samples/sentry-samples-spring-7/src/main/java/io/sentry/samples/spring7/SentryConfig.java @@ -12,7 +12,6 @@ // project/dashboard @EnableSentry( dsn = "https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563", - sendDefaultPii = true, maxRequestBodySize = SentryOptions.RequestSize.MEDIUM) @Import(SentryTracingConfiguration.class) public class SentryConfig { diff --git a/sentry-samples/sentry-samples-spring-boot-4-log4j2/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-4-log4j2/src/main/resources/application.properties index 426aac28b27..ef1d55a7e65 100644 --- a/sentry-samples/sentry-samples-spring-boot-4-log4j2/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-4-log4j2/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-4-opentelemetry-noagent/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-4-opentelemetry-noagent/src/main/resources/application.properties index c21e62a6285..d0e1faa71a9 100644 --- a/sentry-samples/sentry-samples-spring-boot-4-opentelemetry-noagent/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-4-opentelemetry-noagent/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-4-opentelemetry/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-4-opentelemetry/src/main/resources/application.properties index 0867acf41d6..6c49a2b67e4 100644 --- a/sentry-samples/sentry-samples-spring-boot-4-opentelemetry/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-4-opentelemetry/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-4-otlp/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-4-otlp/src/main/resources/application.properties index a49f6244ad7..3586f863250 100644 --- a/sentry-samples/sentry-samples-spring-boot-4-otlp/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-4-otlp/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-4-webflux/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-4-webflux/src/main/resources/application.properties index cb54e513d93..4c646a01247 100644 --- a/sentry-samples/sentry-samples-spring-boot-4-webflux/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-4-webflux/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.debug=true # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-4/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-4/src/main/resources/application.properties index d2bc6cec3de..5e8e30aa126 100644 --- a/sentry-samples/sentry-samples-spring-boot-4/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-4/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-log4j2/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-jakarta-log4j2/src/main/resources/application.properties index 8bd8046d2d0..32eb02dd72d 100644 --- a/sentry-samples/sentry-samples-spring-boot-jakarta-log4j2/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-log4j2/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties index 1e056aead2c..4768e3a96e0 100644 --- a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/resources/application.properties index 22b7ced935d..ed0adab2b16 100644 --- a/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application.properties index 1d5ff37713b..feb85aaef31 100644 --- a/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-jakarta/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties index 5b739ad4047..cc3060b8365 100644 --- a/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-opentelemetry-noagent/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-opentelemetry/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-opentelemetry/src/main/resources/application.properties index ffdfa4fa28b..e267f26e0ad 100644 --- a/sentry-samples/sentry-samples-spring-boot-opentelemetry/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-opentelemetry/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-webflux-jakarta/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-webflux-jakarta/src/main/resources/application.properties index bd1df844351..8a0ca2f2694 100644 --- a/sentry-samples/sentry-samples-spring-boot-webflux-jakarta/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-webflux-jakarta/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.debug=true # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot-webflux/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot-webflux/src/main/resources/application.properties index d8ff798353c..2a5b8a62db5 100644 --- a/sentry-samples/sentry-samples-spring-boot-webflux/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot-webflux/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.debug=true # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-boot/src/main/resources/application.properties b/sentry-samples/sentry-samples-spring-boot/src/main/resources/application.properties index 25a8ddb20a3..af71f74072f 100644 --- a/sentry-samples/sentry-samples-spring-boot/src/main/resources/application.properties +++ b/sentry-samples/sentry-samples-spring-boot/src/main/resources/application.properties @@ -1,6 +1,5 @@ # NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry project/dashboard sentry.dsn=https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563 -sentry.send-default-pii=true sentry.max-request-body-size=medium # Sentry Spring Boot integration allows more fine-grained SentryOptions configuration sentry.max-breadcrumbs=150 diff --git a/sentry-samples/sentry-samples-spring-jakarta/src/main/java/io/sentry/samples/spring/jakarta/SentryConfig.java b/sentry-samples/sentry-samples-spring-jakarta/src/main/java/io/sentry/samples/spring/jakarta/SentryConfig.java index 443299048f3..457bb1034bf 100644 --- a/sentry-samples/sentry-samples-spring-jakarta/src/main/java/io/sentry/samples/spring/jakarta/SentryConfig.java +++ b/sentry-samples/sentry-samples-spring-jakarta/src/main/java/io/sentry/samples/spring/jakarta/SentryConfig.java @@ -12,7 +12,6 @@ // project/dashboard @EnableSentry( dsn = "https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563", - sendDefaultPii = true, maxRequestBodySize = SentryOptions.RequestSize.MEDIUM) @Import(SentryTracingConfiguration.class) public class SentryConfig { diff --git a/sentry-samples/sentry-samples-spring/src/main/java/io/sentry/samples/spring/SentryConfig.java b/sentry-samples/sentry-samples-spring/src/main/java/io/sentry/samples/spring/SentryConfig.java index e350d7aab94..cf6029864fc 100644 --- a/sentry-samples/sentry-samples-spring/src/main/java/io/sentry/samples/spring/SentryConfig.java +++ b/sentry-samples/sentry-samples-spring/src/main/java/io/sentry/samples/spring/SentryConfig.java @@ -12,7 +12,6 @@ // project/dashboard @EnableSentry( dsn = "https://502f25099c204a2fbf4cb16edc5975d1@o447951.ingest.sentry.io/5428563", - sendDefaultPii = true, maxRequestBodySize = SentryOptions.RequestSize.MEDIUM) @Import(SentryTracingConfiguration.class) public class SentryConfig { diff --git a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java index 0dea8ee2bfa..7d727664cd3 100644 --- a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java @@ -5,6 +5,7 @@ import io.sentry.SentryOptions; import io.sentry.internal.eventprocessor.SentryEventProcessor; import io.sentry.protocol.Request; +import io.sentry.util.CookieUtils; import io.sentry.util.HttpUtils; import io.sentry.util.Objects; import io.sentry.util.UrlUtils; @@ -12,7 +13,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; -import java.util.Locale; +import java.util.List; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,6 +43,12 @@ public SentryRequestHttpServletRequestProcessor( UrlUtils.filterQueryParams( httpRequest.getQueryString(), options.getDataCollectionResolver())); sentryRequest.setHeaders(resolveHeadersMap(httpRequest)); + final @Nullable List cookies = + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders(CookieUtils.COOKIE_HEADER_NAME), + options.getDataCollectionResolver().getCookies(), + Collections.emptyList()); + sentryRequest.setCookies(cookies == null ? null : String.join(",", cookies)); event.setRequest(sentryRequest); return event; @@ -51,16 +58,10 @@ public SentryRequestHttpServletRequestProcessor( final @NotNull HttpServletRequest request) { final Map headersMap = new HashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { - if (options.getDataCollectionResolver().isDataCollectionConfigured() - || !HttpUtils.containsSensitiveHeader(headerName.toUpperCase(Locale.ROOT))) { - headersMap.put(headerName, toString(request.getHeaders(headerName))); - } + headersMap.put(headerName, toString(request.getHeaders(headerName))); } - if (options.getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, options.getDataCollectionResolver().getHttpRequestHeaders()); - } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, options.getDataCollectionResolver().getHttpRequestHeaders()); } private static @Nullable String toString(final @Nullable Enumeration enumeration) { diff --git a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt index 0aa9228530e..401ae861da5 100644 --- a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt @@ -9,9 +9,7 @@ import java.net.URI import java.util.Collections import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.test.assertFalse import kotlin.test.assertNotNull -import kotlin.test.assertNull import kotlin.test.assertTrue import org.mockito.kotlin.any import org.mockito.kotlin.mock @@ -59,17 +57,15 @@ class SentryRequestHttpServletRequestProcessorTest { } @Test - fun `does not attach cookies`() { + fun `attaches cookies by default`() { val request = mockRequest(url = "http://example.com?param1=xyz", headers = mapOf("Cookie" to "name=value")) - val sentryOptions = SentryOptions() - sentryOptions.isSendDefaultPii = false - val eventProcessor = SentryRequestHttpServletRequestProcessor(request, sentryOptions) + val eventProcessor = SentryRequestHttpServletRequestProcessor(request, SentryOptions()) val event = SentryEvent() eventProcessor.process(event, Hint()) - assertNotNull(event.request) { assertNull(it.cookies) } + assertNotNull(event.request) { assertEquals("name=value", it.cookies) } } @Test @@ -118,7 +114,7 @@ class SentryRequestHttpServletRequestProcessorTest { } @Test - fun `does not attach sensitive headers`() { + fun `filters sensitive headers`() { val request = mockRequest( url = "http://example.com?param1=xyz", @@ -131,19 +127,17 @@ class SentryRequestHttpServletRequestProcessorTest { "Cookie" to "some cookies", ), ) - val sentryOptions = SentryOptions() - sentryOptions.isSendDefaultPii = false - val eventProcessor = SentryRequestHttpServletRequestProcessor(request, sentryOptions) + val eventProcessor = SentryRequestHttpServletRequestProcessor(request, SentryOptions()) val event = SentryEvent() eventProcessor.process(event, Hint()) assertNotNull(event.request) { req -> assertNotNull(req.headers) { - assertFalse(it.containsKey("X-FORWARDED-FOR")) - assertFalse(it.containsKey("Authorization")) - assertFalse(it.containsKey("authorization")) - assertFalse(it.containsKey("Cookies")) + assertEquals("192.168.0.1", it["X-FORWARDED-FOR"]) + assertEquals("[Filtered]", it["Authorization"]) + assertEquals("[Filtered]", it["authorization"]) + assertEquals("[Filtered]", it["Cookie"]) assertTrue(it.containsKey("some-header")) } } diff --git a/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java b/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java index d8a2fcd808c..ad2c58e2202 100644 --- a/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java @@ -5,13 +5,14 @@ import io.sentry.SentryOptions; import io.sentry.internal.eventprocessor.SentryEventProcessor; import io.sentry.protocol.Request; +import io.sentry.util.CookieUtils; import io.sentry.util.HttpUtils; import io.sentry.util.Objects; import io.sentry.util.UrlUtils; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; -import java.util.Locale; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.jetbrains.annotations.NotNull; @@ -42,6 +43,12 @@ public SentryRequestHttpServletRequestProcessor( UrlUtils.filterQueryParams( httpRequest.getQueryString(), options.getDataCollectionResolver())); sentryRequest.setHeaders(resolveHeadersMap(httpRequest)); + final @Nullable List cookies = + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders(CookieUtils.COOKIE_HEADER_NAME), + options.getDataCollectionResolver().getCookies(), + Collections.emptyList()); + sentryRequest.setCookies(cookies == null ? null : String.join(",", cookies)); event.setRequest(sentryRequest); return event; @@ -51,16 +58,10 @@ public SentryRequestHttpServletRequestProcessor( final @NotNull HttpServletRequest request) { final Map headersMap = new HashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { - if (options.getDataCollectionResolver().isDataCollectionConfigured() - || !HttpUtils.containsSensitiveHeader(headerName.toUpperCase(Locale.ROOT))) { - headersMap.put(headerName, toString(request.getHeaders(headerName))); - } + headersMap.put(headerName, toString(request.getHeaders(headerName))); } - if (options.getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, options.getDataCollectionResolver().getHttpRequestHeaders()); - } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, options.getDataCollectionResolver().getHttpRequestHeaders()); } private static @Nullable String toString(final @Nullable Enumeration enumeration) { diff --git a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt index c3861ed145e..8cf448ae277 100644 --- a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt @@ -7,7 +7,6 @@ import io.sentry.SentryOptions import java.net.URI import kotlin.test.Test import kotlin.test.assertEquals -import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue @@ -83,19 +82,17 @@ class SentryRequestHttpServletRequestProcessorTest { } @Test - fun `does not attach cookies`() { + fun `attaches cookies by default`() { val request = MockMvcRequestBuilders.get(URI.create("http://example.com?param1=xyz")) .header("Cookie", "name=value") .buildRequest(MockServletContext()) - val sentryOptions = SentryOptions() - sentryOptions.isSendDefaultPii = false - val eventProcessor = SentryRequestHttpServletRequestProcessor(request, sentryOptions) + val eventProcessor = SentryRequestHttpServletRequestProcessor(request, SentryOptions()) val event = SentryEvent() eventProcessor.process(event, Hint()) - assertNotNull(event.request) { assertNull(it.cookies) } + assertNotNull(event.request) { assertEquals("name=value", it.cookies) } } @Test @@ -142,28 +139,24 @@ class SentryRequestHttpServletRequestProcessorTest { } @Test - fun `does not attach sensitive headers`() { + fun `filters sensitive headers`() { val request = MockMvcRequestBuilders.get(URI.create("http://example.com?param1=xyz")) .header("some-header", "some-header value") .header("X-FORWARDED-FOR", "192.168.0.1") .header("authorization", "Token") - .header("Authorization", "Token") .header("Cookie", "some cookies") .buildRequest(MockServletContext()) - val sentryOptions = SentryOptions() - sentryOptions.isSendDefaultPii = false - val eventProcessor = SentryRequestHttpServletRequestProcessor(request, sentryOptions) + val eventProcessor = SentryRequestHttpServletRequestProcessor(request, SentryOptions()) val event = SentryEvent() eventProcessor.process(event, Hint()) assertNotNull(event.request) { req -> assertNotNull(req.headers) { - assertFalse(it.containsKey("X-FORWARDED-FOR")) - assertFalse(it.containsKey("Authorization")) - assertFalse(it.containsKey("authorization")) - assertFalse(it.containsKey("Cookies")) + assertEquals("192.168.0.1", it["X-FORWARDED-FOR"]) + assertEquals("[Filtered]", it["authorization"]) + assertEquals("[Filtered]", it["Cookie"]) assertTrue(it.containsKey("some-header")) } } diff --git a/sentry-spring-7/api/sentry-spring-7.api b/sentry-spring-7/api/sentry-spring-7.api index a781ee47096..ebccaeee3d4 100644 --- a/sentry-spring-7/api/sentry-spring-7.api +++ b/sentry-spring-7/api/sentry-spring-7.api @@ -13,7 +13,6 @@ public abstract interface annotation class io/sentry/spring7/EnableSentry : java public abstract fun dsn ()Ljava/lang/String; public abstract fun exceptionResolverOrder ()I public abstract fun maxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize; - public abstract fun sendDefaultPii ()Z } public final class io/sentry/spring7/HttpServletRequestSentryUserProvider : io/sentry/spring7/SentryUserProvider { diff --git a/sentry-spring-7/src/integrationTest/kotlin/io/sentry/spring7/integrationtest/IntegrationTestApplication.kt b/sentry-spring-7/src/integrationTest/kotlin/io/sentry/spring7/integrationtest/IntegrationTestApplication.kt index 251d3b01899..2311ff9b141 100644 --- a/sentry-spring-7/src/integrationTest/kotlin/io/sentry/spring7/integrationtest/IntegrationTestApplication.kt +++ b/sentry-spring-7/src/integrationTest/kotlin/io/sentry/spring7/integrationtest/IntegrationTestApplication.kt @@ -32,7 +32,7 @@ class AppInitializer : AbstractAnnotationConfigDispatcherServletInitializer() { // The DSN and the traces path come from system properties, and the other options from // sentry.properties, all of which Sentry reads as external configuration. -@Configuration @EnableSentry(dsn = "", sendDefaultPii = true) open class AppConfig +@Configuration @EnableSentry(dsn = "") open class AppConfig // Declares the controllers rather than scanning for them, which would also pick up AppConfig and // initialize Sentry a second time in the servlet's context. diff --git a/sentry-spring-7/src/main/java/io/sentry/spring7/EnableSentry.java b/sentry-spring-7/src/main/java/io/sentry/spring7/EnableSentry.java index f65e91d3016..cd6c33dc877 100644 --- a/sentry-spring-7/src/main/java/io/sentry/spring7/EnableSentry.java +++ b/sentry-spring-7/src/main/java/io/sentry/spring7/EnableSentry.java @@ -30,13 +30,6 @@ */ String dsn() default ""; - /** - * Whether to send personal identifiable information along with events. - * - * @return true if send default PII or false otherwise. - */ - boolean sendDefaultPii() default false; - /** * Determines whether all web exceptions are reported or only uncaught exceptions. * diff --git a/sentry-spring-7/src/main/java/io/sentry/spring7/SentryHubRegistrar.java b/sentry-spring-7/src/main/java/io/sentry/spring7/SentryHubRegistrar.java index 72e69b18447..a8c80e2bacf 100644 --- a/sentry-spring-7/src/main/java/io/sentry/spring7/SentryHubRegistrar.java +++ b/sentry-spring-7/src/main/java/io/sentry/spring7/SentryHubRegistrar.java @@ -54,9 +54,6 @@ private void registerSentryOptions( builder.addPropertyValue("sdkVersion", createSdkVersion()); builder.addPropertyValue("initPriority", InitPriority.LOW); addPackageAndIntegrationInfo(); - if (annotationAttributes.containsKey("sendDefaultPii")) { - builder.addPropertyValue("sendDefaultPii", annotationAttributes.getBoolean("sendDefaultPii")); - } if (annotationAttributes.containsKey("maxRequestBodySize")) { builder.addPropertyValue( "maxRequestBodySize", annotationAttributes.get("maxRequestBodySize")); diff --git a/sentry-spring-7/src/main/java/io/sentry/spring7/SentryRequestResolver.java b/sentry-spring-7/src/main/java/io/sentry/spring7/SentryRequestResolver.java index 4995d4bfe09..2a38f2a59f5 100644 --- a/sentry-spring-7/src/main/java/io/sentry/spring7/SentryRequestResolver.java +++ b/sentry-spring-7/src/main/java/io/sentry/spring7/SentryRequestResolver.java @@ -51,19 +51,12 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { sentryRequest.setHeaders(resolveHeadersMap(httpRequest, additionalSecurityCookieNames)); final @NotNull String cookieName = CookieUtils.COOKIE_HEADER_NAME; - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterCookiesFromHeader( - httpRequest.getHeaders(cookieName), - scopes.getOptions().getDataCollectionResolver().getCookies(), - additionalSecurityCookieNames))); - } else if (scopes.getOptions().isSendDefaultPii()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - httpRequest.getHeaders(cookieName), cookieName, additionalSecurityCookieNames))); - } + sentryRequest.setCookies( + toString( + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders(cookieName), + scopes.getOptions().getDataCollectionResolver().getCookies(), + additionalSecurityCookieNames))); return sentryRequest; } @@ -73,20 +66,13 @@ Map resolveHeadersMap( final @NotNull List additionalSecurityCookieNames) { final Map headersMap = new HashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured() - || scopes.getOptions().isSendDefaultPii() - || !HttpUtils.containsSensitiveHeader(headerName)) { - final @Nullable List filteredHeaders = - CookieUtils.filterOutSecurityCookiesFromHeader( - request.getHeaders(headerName), headerName, additionalSecurityCookieNames); - headersMap.put(headerName, toString(filteredHeaders)); - } - } - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); + final @Nullable List filteredHeaders = + CookieUtils.filterOutSecurityCookiesFromHeader( + request.getHeaders(headerName), headerName, additionalSecurityCookieNames); + headersMap.put(headerName, toString(filteredHeaders)); } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); } private List extractSecurityCookieNamesOrUseCached( diff --git a/sentry-spring-7/src/main/java/io/sentry/spring7/tracing/SentrySpanClientWebRequestFilter.java b/sentry-spring-7/src/main/java/io/sentry/spring7/tracing/SentrySpanClientWebRequestFilter.java index 2515288721c..58e2bb35b68 100644 --- a/sentry-spring-7/src/main/java/io/sentry/spring7/tracing/SentrySpanClientWebRequestFilter.java +++ b/sentry-spring-7/src/main/java/io/sentry/spring7/tracing/SentrySpanClientWebRequestFilter.java @@ -51,9 +51,7 @@ public SentrySpanClientWebRequestFilter(final @NotNull IScopes scopes) { final @NotNull String method = request.method().name(); span.setDescription(method + " " + urlDetails.getUrlOrFallback()); span.setData(SpanDataConvention.HTTP_METHOD_KEY, method.toUpperCase(Locale.ROOT)); - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - urlDetails.applyToSpan(span); - } + urlDetails.applyToSpan(span); final @NotNull ClientRequest modifiedRequest = maybeAddTracingHeaders(request, span); diff --git a/sentry-spring-7/src/main/java/io/sentry/spring7/webflux/SentryRequestResolver.java b/sentry-spring-7/src/main/java/io/sentry/spring7/webflux/SentryRequestResolver.java index c9ea5c6c7de..fe5b6da079d 100644 --- a/sentry-spring-7/src/main/java/io/sentry/spring7/webflux/SentryRequestResolver.java +++ b/sentry-spring-7/src/main/java/io/sentry/spring7/webflux/SentryRequestResolver.java @@ -40,19 +40,12 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { sentryRequest.setHeaders(resolveHeadersMap(httpRequest.getHeaders())); final @NotNull String headerName = CookieUtils.COOKIE_HEADER_NAME; - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterCookiesFromHeader( - httpRequest.getHeaders().get(headerName), - scopes.getOptions().getDataCollectionResolver().getCookies(), - Collections.emptyList()))); - } else if (scopes.getOptions().isSendDefaultPii()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - httpRequest.getHeaders().get(headerName), headerName, Collections.emptyList()))); - } + sentryRequest.setCookies( + toString( + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders().get(headerName), + scopes.getOptions().getDataCollectionResolver().getCookies(), + Collections.emptyList()))); return sentryRequest; } @@ -60,22 +53,15 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { Map resolveHeadersMap(final HttpHeaders request) { final Map headersMap = new HashMap<>(); for (Map.Entry> entry : request.headerSet()) { - String headerName = entry.getKey(); - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured() - || scopes.getOptions().isSendDefaultPii() - || !HttpUtils.containsSensitiveHeader(headerName)) { - headersMap.put( - headerName, - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - entry.getValue(), headerName, Collections.emptyList()))); - } - } - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); + final String headerName = entry.getKey(); + headersMap.put( + headerName, + toString( + CookieUtils.filterOutSecurityCookiesFromHeader( + entry.getValue(), headerName, Collections.emptyList()))); } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); } private static @Nullable String toString(final @Nullable List enumeration) { diff --git a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/EnableSentryTest.kt b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/EnableSentryTest.kt index 4c782ef7a64..d1e2ab5ac9b 100644 --- a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/EnableSentryTest.kt +++ b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/EnableSentryTest.kt @@ -21,23 +21,17 @@ class EnableSentryTest { ApplicationContextRunner().withConfiguration(UserConfigurations.of(AppConfig::class.java)) @Test - fun `sets properties from environment on SentryOptions`() { - ApplicationContextRunner() - .withConfiguration(UserConfigurations.of(AppConfigWithDefaultSendPii::class.java)) - .run { - assertThat(it).hasSingleBean(SentryOptions::class.java) - val options = it.getBean(SentryOptions::class.java) - assertThat(options.dsn).isEqualTo("http://key@localhost/proj") - assertThat(options.isSendDefaultPii).isTrue() - } + fun `sets dsn from annotation on SentryOptions`() { + contextRunner.run { + assertThat(it).hasSingleBean(SentryOptions::class.java) + assertThat(it.getBean(SentryOptions::class.java).dsn).isEqualTo("http://key@localhost/proj") + } ApplicationContextRunner() .withConfiguration(UserConfigurations.of(AppConfigWithEmptyDsn::class.java)) .run { assertThat(it).hasSingleBean(SentryOptions::class.java) - val options = it.getBean(SentryOptions::class.java) - assertThat(options.dsn).isEmpty() - assertThat(options.isSendDefaultPii).isFalse() + assertThat(it.getBean(SentryOptions::class.java).dsn).isEmpty() } } @@ -181,9 +175,6 @@ class EnableSentryTest { @EnableSentry(dsn = "") class AppConfigWithEmptyDsn - @EnableSentry(dsn = "http://key@localhost/proj", sendDefaultPii = true) - class AppConfigWithDefaultSendPii - @EnableSentry(dsn = "http://key@localhost/proj", exceptionResolverOrder = Integer.MAX_VALUE) class AppConfigWithExceptionResolverOrderIntegerMaxValue diff --git a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/HttpServletRequestSentryUserProviderTest.kt b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/HttpServletRequestSentryUserProviderTest.kt index 16bddd0c27e..f5a0829d6c4 100644 --- a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/HttpServletRequestSentryUserProviderTest.kt +++ b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/HttpServletRequestSentryUserProviderTest.kt @@ -19,9 +19,7 @@ class HttpServletRequestSentryUserProviderTest { request.addHeader("X-FORWARDED-FOR", "192.168.0.1,192.168.0.2") RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = SentryOptions() - options.isSendDefaultPii = true - val userProvider = HttpServletRequestSentryUserProvider(options) + val userProvider = HttpServletRequestSentryUserProvider(SentryOptions()) val result = userProvider.provideUser() assertNotNull(result) @@ -36,9 +34,7 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = SentryOptions() - options.isSendDefaultPii = true - val userProvider = HttpServletRequestSentryUserProvider(options) + val userProvider = HttpServletRequestSentryUserProvider(SentryOptions()) val result = userProvider.provideUser() assertNotNull(result) @@ -53,11 +49,7 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = - SentryOptions().apply { - isSendDefaultPii = true - dataCollection.setUserInfo(false) - } + val options = SentryOptions().apply { dataCollection.setUserInfo(false) } val result = HttpServletRequestSentryUserProvider(options).provideUser() assertNull(result) @@ -71,30 +63,10 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = - SentryOptions().apply { - isSendDefaultPii = false - dataCollection.setUserInfo(true) - } + val options = SentryOptions().apply { dataCollection.setUserInfo(true) } val result = HttpServletRequestSentryUserProvider(options).provideUser() assertNotNull(result) assertEquals("janesmith", result.username) } - - @Test - fun `when sendDefaultPii is set to false, does not attach user data Sentry Event`() { - val principal = mock() - whenever(principal.name).thenReturn("janesmith") - val request = MockHttpServletRequest() - request.userPrincipal = principal - RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - - val options = SentryOptions() - options.isSendDefaultPii = false - val userProvider = HttpServletRequestSentryUserProvider(options) - val result = userProvider.provideUser() - - assertNull(result) - } } diff --git a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentrySpringFilterTest.kt b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentrySpringFilterTest.kt index dd23bd933f4..a2ae86e3e3a 100644 --- a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentrySpringFilterTest.kt +++ b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentrySpringFilterTest.kt @@ -22,7 +22,6 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNotNull -import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.test.fail import org.assertj.core.api.Assertions @@ -168,8 +167,8 @@ class SentrySpringFilterTest { } @Test - fun `when sendDefaultPii is set to true, attaches filtered cookies to Scope request`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = true } + fun `attaches filtered cookies to Scope request by default`() { + val sentryOptions = SentryOptions() val listener = fixture.getSut( @@ -187,28 +186,10 @@ class SentrySpringFilterTest { val expectedCookieString = "name=value; JSESSIONID=[Filtered]; mysessioncookiename=[Filtered],name2=value2; SID=[Filtered]" assertEquals(expectedCookieString, it.cookies) - assertEquals(expectedCookieString, it.headers!!["Cookie"]) + assertEquals("[Filtered]", it.headers!!["Cookie"]) } } - @Test - fun `when sendDefaultPii is set to false, does not attach cookies to Scope request`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = false } - - val listener = - fixture.getSut( - request = - MockMvcRequestBuilders.get(URI.create("http://example.com?param1=xyz")) - .header("Cookie", "name=value") - .buildRequest(MockServletContext()), - options = sentryOptions, - ) - - listener.doFilter(fixture.request, fixture.response, fixture.chain) - - assertNotNull(fixture.scope.request) { assertNull(it.cookies) } - } - @Test fun `data collection filters request headers`() { val sentryOptions = @@ -234,8 +215,8 @@ class SentrySpringFilterTest { } @Test - fun `when sendDefaultPii is set to false, does not attach sensitive headers`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = false } + fun `filters sensitive headers by default`() { + val sentryOptions = SentryOptions() val listener = fixture.getSut( @@ -244,7 +225,6 @@ class SentrySpringFilterTest { .header("some-header", "some-header value") .header("X-FORWARDED-FOR", "192.168.0.1") .header("authorization", "Token") - .header("Authorization", "Token") .header("Cookie", "some cookies") .buildRequest(MockServletContext()), options = sentryOptions, @@ -254,10 +234,9 @@ class SentrySpringFilterTest { assertNotNull(fixture.scope.request) { request -> assertNotNull(request.headers) { - assertFalse(it.containsKey("X-FORWARDED-FOR")) - assertFalse(it.containsKey("Authorization")) - assertFalse(it.containsKey("authorization")) - assertFalse(it.containsKey("Cookie")) + assertEquals("192.168.0.1", it["X-FORWARDED-FOR"]) + assertEquals("[Filtered]", it["authorization"]) + assertEquals("[Filtered]", it["Cookie"]) assertTrue(it.containsKey("some-header")) } } @@ -266,7 +245,6 @@ class SentrySpringFilterTest { @Test fun `caches request depending on the maxRequestBodySize value and request body length`() { data class TestParams( - val sendDefaultPii: Boolean = true, val maxRequestBodySize: SentryOptions.RequestSize, val body: String, val contentType: String = "application/json", @@ -276,12 +254,6 @@ class SentrySpringFilterTest { val params = listOf( TestParams(maxRequestBodySize = NONE, body = "xxx", expectedToBeCached = false), - TestParams( - maxRequestBodySize = SMALL, - body = "xxx", - expectedToBeCached = false, - sendDefaultPii = false, - ), TestParams(maxRequestBodySize = SMALL, body = "xxx", expectedToBeCached = true), TestParams( maxRequestBodySize = SMALL, @@ -318,11 +290,7 @@ class SentrySpringFilterTest { params.forEach { param -> try { val fixture = Fixture() - val sentryOptions = - SentryOptions().apply { - maxRequestBodySize = param.maxRequestBodySize - isSendDefaultPii = param.sendDefaultPii - } + val sentryOptions = SentryOptions().apply { maxRequestBodySize = param.maxRequestBodySize } val listener = fixture.getSut( @@ -349,10 +317,9 @@ class SentrySpringFilterTest { } @Test - fun `data collection can enable request body when sendDefaultPii is false`() { + fun `data collection can enable request body`() { val options = SentryOptions().apply { - isSendDefaultPii = false maxRequestBodySize = SMALL dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_REQUEST) } @@ -372,10 +339,9 @@ class SentrySpringFilterTest { } @Test - fun `data collection can disable request body when sendDefaultPii is true`() { + fun `data collection can disable request body`() { val options = SentryOptions().apply { - isSendDefaultPii = true maxRequestBodySize = SMALL dataCollection.httpBodies = emptySet() } diff --git a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentryUserFilterTest.kt b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentryUserFilterTest.kt index 36fb28c5717..8c174d82806 100644 --- a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentryUserFilterTest.kt +++ b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SentryUserFilterTest.kt @@ -25,15 +25,10 @@ class SentryUserFilterTest { val chain = mock() fun getSut( - isSendDefaultPii: Boolean = false, userInfo: Boolean? = null, userProviders: List, ): SentryUserFilter { - val options = - SentryOptions().apply { - this.isSendDefaultPii = isSendDefaultPii - userInfo?.let { dataCollection.setUserInfo(it) } - } + val options = SentryOptions().apply { userInfo?.let { dataCollection.setUserInfo(it) } } whenever(scopes.options).thenReturn(options) return SentryUserFilter(scopes, userProviders) } @@ -101,10 +96,9 @@ class SentryUserFilterTest { } @Test - fun `when isSendDefaultPii is true and user is set with custom ip address, user ip is unchanged`() { + fun `when user is set with custom ip address, user ip is unchanged`() { val filter = fixture.getSut( - isSendDefaultPii = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "192.168.0.1" } }), ) @@ -114,10 +108,9 @@ class SentryUserFilterTest { } @Test - fun `when isSendDefaultPii is true and user is set with {{auto}} ip address, user ip is set to null`() { + fun `when user is set with {{auto}} ip address, user ip is set to null`() { val filter = fixture.getSut( - isSendDefaultPii = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) @@ -130,7 +123,6 @@ class SentryUserFilterTest { fun `when user info is disabled, preserves auto ip from a custom provider`() { val filter = fixture.getSut( - isSendDefaultPii = true, userInfo = false, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) @@ -144,7 +136,6 @@ class SentryUserFilterTest { fun `when user info is enabled, removes auto ip from a custom provider`() { val filter = fixture.getSut( - isSendDefaultPii = false, userInfo = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) diff --git a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SpringSecuritySentryUserProviderTest.kt b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SpringSecuritySentryUserProviderTest.kt index ca931ce3b8f..72248a3169c 100644 --- a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SpringSecuritySentryUserProviderTest.kt +++ b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/SpringSecuritySentryUserProviderTest.kt @@ -14,15 +14,10 @@ import org.springframework.security.core.context.SecurityContextHolder class SpringSecuritySentryUserProviderTest { class Fixture { fun getSut( - isSendDefaultPii: Boolean = true, username: String? = null, userInfo: Boolean? = null, ): SpringSecuritySentryUserProvider { - val options = - SentryOptions().apply { - this.isSendDefaultPii = isSendDefaultPii - userInfo?.let { dataCollection.setUserInfo(it) } - } + val options = SentryOptions().apply { userInfo?.let { dataCollection.setUserInfo(it) } } val securityContext = mock() if (username != null) { val authentication = mock() @@ -39,36 +34,29 @@ class SpringSecuritySentryUserProviderTest { private val fixture = Fixture() @Test - fun `when send default pii is set to true, returns user with username set`() { - val provider = fixture.getSut(true, "name") + fun `returns user with username set by default`() { + val provider = fixture.getSut(username = "name") val user = provider.provideUser() assertNotNull(user) { assertEquals("name", it.username) } } @Test - fun `when send default pii is set to false, returns null`() { - val provider = fixture.getSut(false) - val user = provider.provideUser() - assertNull(user) - } - - @Test - fun `when user info is disabled, returns null even if sendDefaultPii is true`() { - val provider = fixture.getSut(isSendDefaultPii = true, username = "name", userInfo = false) + fun `when user info is disabled, returns null`() { + val provider = fixture.getSut(username = "name", userInfo = false) assertNull(provider.provideUser()) } @Test - fun `when user info is enabled, returns user even if sendDefaultPii is false`() { - val provider = fixture.getSut(isSendDefaultPii = false, username = "name", userInfo = true) + fun `when user info is enabled, returns user`() { + val provider = fixture.getSut(username = "name", userInfo = true) assertNotNull(provider.provideUser()) { assertEquals("name", it.username) } } @Test - fun `when send default pii is set to true and security context is not set, returns null`() { - val provider = fixture.getSut(true) + fun `when security context is not set, returns null`() { + val provider = fixture.getSut() val user = provider.provideUser() assertNull(user) } diff --git a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/mvc/SentrySpringIntegrationTest.kt b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/mvc/SentrySpringIntegrationTest.kt index 36e6af289fd..1ec72efc73e 100644 --- a/sentry-spring-7/src/test/kotlin/io/sentry/spring7/mvc/SentrySpringIntegrationTest.kt +++ b/sentry-spring-7/src/test/kotlin/io/sentry/spring7/mvc/SentrySpringIntegrationTest.kt @@ -390,7 +390,6 @@ class SentrySpringIntegrationTest { @SpringBootApplication @EnableSentry( dsn = "http://key@localhost/proj", - sendDefaultPii = true, maxRequestBodySize = SentryOptions.RequestSize.MEDIUM, ) @Import(SentryTracingConfiguration::class, SentryCaptureExceptionParameterConfiguration::class) diff --git a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt index 94b23aa29af..99770a67e55 100644 --- a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt @@ -654,7 +654,7 @@ class SentryAutoConfigurationTest { @Test fun `when custom SentryUserProvider bean is configured, it's added after HttpServletRequestSentryUserProvider`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withConfiguration(UserConfigurations.of(SentryUserProviderConfiguration::class.java)) .run { val userProviders = it.getSentryUserProviders() @@ -668,7 +668,7 @@ class SentryAutoConfigurationTest { @Test fun `when custom SentryUserProvider bean with higher order is configured, it's added before HttpServletRequestSentryUserProvider`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withConfiguration( UserConfigurations.of(SentryHighestOrderUserProviderConfiguration::class.java), ) @@ -684,7 +684,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring Security is not on the classpath, SpringSecuritySentryUserProvider is not configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(SecurityContextHolder::class.java)) .run { ctx -> val userProviders = ctx.getSentryUserProviders() @@ -696,7 +696,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring MVC is not on the classpath, SentryExceptionResolver is not configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(HandlerExceptionResolver::class.java)) .run { assertThat(it).doesNotHaveBean(SentryExceptionResolver::class.java) } } @@ -704,7 +704,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring MVC is not on the classpath, fallback TransactionNameProvider is configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(HandlerExceptionResolver::class.java)) .run { assertThat(it.getBean(TransactionNameProvider::class.java)) diff --git a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/it/SentrySpringIntegrationTest.kt b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/it/SentrySpringIntegrationTest.kt index 473b60def12..84f86e94510 100644 --- a/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/it/SentrySpringIntegrationTest.kt +++ b/sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/it/SentrySpringIntegrationTest.kt @@ -59,7 +59,6 @@ import org.springframework.web.bind.annotation.RestController properties = [ "sentry.dsn=http://key@localhost/proj", - "sentry.send-default-pii=true", "sentry.traces-sample-rate=1.0", "sentry.max-request-body-size=medium", "sentry.enable-backpressure-handling=false", diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt index 3f434d1ac4d..0860975f944 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt @@ -673,7 +673,7 @@ class SentryAutoConfigurationTest { @Test fun `when custom SentryUserProvider bean is configured, it's added after HttpServletRequestSentryUserProvider`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withConfiguration(UserConfigurations.of(SentryUserProviderConfiguration::class.java)) .run { val userProviders = it.getSentryUserProviders() @@ -687,7 +687,7 @@ class SentryAutoConfigurationTest { @Test fun `when custom SentryUserProvider bean with higher order is configured, it's added before HttpServletRequestSentryUserProvider`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withConfiguration( UserConfigurations.of(SentryHighestOrderUserProviderConfiguration::class.java), ) @@ -703,7 +703,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring Security is not on the classpath, SpringSecuritySentryUserProvider is not configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(SecurityContextHolder::class.java)) .run { ctx -> val userProviders = ctx.getSentryUserProviders() @@ -715,7 +715,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring MVC is not on the classpath, SentryExceptionResolver is not configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(HandlerExceptionResolver::class.java)) .run { assertThat(it).doesNotHaveBean(SentryExceptionResolver::class.java) } } @@ -723,7 +723,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring MVC is not on the classpath, fallback TransactionNameProvider is configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(HandlerExceptionResolver::class.java)) .run { assertThat(it.getBean(TransactionNameProvider::class.java)) diff --git a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/it/SentrySpringIntegrationTest.kt b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/it/SentrySpringIntegrationTest.kt index 89d378d2087..67c8a6d8a66 100644 --- a/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/it/SentrySpringIntegrationTest.kt +++ b/sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/it/SentrySpringIntegrationTest.kt @@ -59,7 +59,6 @@ import org.springframework.web.bind.annotation.RestController properties = [ "sentry.dsn=http://key@localhost/proj", - "sentry.send-default-pii=true", "sentry.traces-sample-rate=1.0", "sentry.max-request-body-size=medium", "sentry.enable-backpressure-handling=false", diff --git a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 00ace5073e2..f670ddee746 100644 --- a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -671,7 +671,7 @@ class SentryAutoConfigurationTest { @Test fun `when custom SentryUserProvider bean is configured, it's added after HttpServletRequestSentryUserProvider`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withConfiguration(UserConfigurations.of(SentryUserProviderConfiguration::class.java)) .run { val userProviders = it.getSentryUserProviders() @@ -685,7 +685,7 @@ class SentryAutoConfigurationTest { @Test fun `when custom SentryUserProvider bean with higher order is configured, it's added before HttpServletRequestSentryUserProvider`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withConfiguration( UserConfigurations.of(SentryHighestOrderUserProviderConfiguration::class.java), ) @@ -701,7 +701,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring Security is not on the classpath, SpringSecuritySentryUserProvider is not configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(SecurityContextHolder::class.java)) .run { ctx -> val userProviders = ctx.getSentryUserProviders() @@ -713,7 +713,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring MVC is not on the classpath, SentryExceptionResolver is not configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(HandlerExceptionResolver::class.java)) .run { assertThat(it).doesNotHaveBean(SentryExceptionResolver::class.java) } } @@ -721,7 +721,7 @@ class SentryAutoConfigurationTest { @Test fun `when Spring MVC is not on the classpath, fallback TransactionNameProvider is configured`() { contextRunner - .withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.send-default-pii=true") + .withPropertyValues("sentry.dsn=http://key@localhost/proj") .withClassLoader(FilteredClassLoader(HandlerExceptionResolver::class.java)) .run { assertThat(it.getBean(TransactionNameProvider::class.java)) diff --git a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/it/SentrySpringIntegrationTest.kt b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/it/SentrySpringIntegrationTest.kt index bba64d3c278..fb4301500a8 100644 --- a/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/it/SentrySpringIntegrationTest.kt +++ b/sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/it/SentrySpringIntegrationTest.kt @@ -59,7 +59,6 @@ import org.springframework.web.bind.annotation.RestController properties = [ "sentry.dsn=http://key@localhost/proj", - "sentry.send-default-pii=true", "sentry.traces-sample-rate=1.0", "sentry.max-request-body-size=medium", "sentry.enable-backpressure-handling=false", diff --git a/sentry-spring-jakarta/api/sentry-spring-jakarta.api b/sentry-spring-jakarta/api/sentry-spring-jakarta.api index fc3064789ef..dfb2d9e3d03 100644 --- a/sentry-spring-jakarta/api/sentry-spring-jakarta.api +++ b/sentry-spring-jakarta/api/sentry-spring-jakarta.api @@ -13,7 +13,6 @@ public abstract interface annotation class io/sentry/spring/jakarta/EnableSentry public abstract fun dsn ()Ljava/lang/String; public abstract fun exceptionResolverOrder ()I public abstract fun maxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize; - public abstract fun sendDefaultPii ()Z } public final class io/sentry/spring/jakarta/HttpServletRequestSentryUserProvider : io/sentry/spring/jakarta/SentryUserProvider { diff --git a/sentry-spring-jakarta/src/integrationTest/kotlin/io/sentry/spring/jakarta/integrationtest/IntegrationTestApplication.kt b/sentry-spring-jakarta/src/integrationTest/kotlin/io/sentry/spring/jakarta/integrationtest/IntegrationTestApplication.kt index 89da9442f1f..2e09ba335a3 100644 --- a/sentry-spring-jakarta/src/integrationTest/kotlin/io/sentry/spring/jakarta/integrationtest/IntegrationTestApplication.kt +++ b/sentry-spring-jakarta/src/integrationTest/kotlin/io/sentry/spring/jakarta/integrationtest/IntegrationTestApplication.kt @@ -32,7 +32,7 @@ class AppInitializer : AbstractAnnotationConfigDispatcherServletInitializer() { // The DSN and the traces path come from system properties, and the other options from // sentry.properties, all of which Sentry reads as external configuration. -@Configuration @EnableSentry(dsn = "", sendDefaultPii = true) open class AppConfig +@Configuration @EnableSentry(dsn = "") open class AppConfig // Declares the controllers rather than scanning for them, which would also pick up AppConfig and // initialize Sentry a second time in the servlet's context. diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/EnableSentry.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/EnableSentry.java index e8cd91f3f44..429ae135063 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/EnableSentry.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/EnableSentry.java @@ -30,13 +30,6 @@ */ String dsn() default ""; - /** - * Whether to send personal identifiable information along with events. - * - * @return true if send default PII or false otherwise. - */ - boolean sendDefaultPii() default false; - /** * Determines whether all web exceptions are reported or only uncaught exceptions. * diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryHubRegistrar.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryHubRegistrar.java index cca74ae2a2d..0ea56547cd3 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryHubRegistrar.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryHubRegistrar.java @@ -54,9 +54,6 @@ private void registerSentryOptions( builder.addPropertyValue("sdkVersion", createSdkVersion()); builder.addPropertyValue("initPriority", InitPriority.LOW); addPackageAndIntegrationInfo(); - if (annotationAttributes.containsKey("sendDefaultPii")) { - builder.addPropertyValue("sendDefaultPii", annotationAttributes.getBoolean("sendDefaultPii")); - } if (annotationAttributes.containsKey("maxRequestBodySize")) { builder.addPropertyValue( "maxRequestBodySize", annotationAttributes.get("maxRequestBodySize")); diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryRequestResolver.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryRequestResolver.java index 9fcb30665cb..2191813a165 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryRequestResolver.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentryRequestResolver.java @@ -51,19 +51,12 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { sentryRequest.setHeaders(resolveHeadersMap(httpRequest, additionalSecurityCookieNames)); final @NotNull String cookieName = CookieUtils.COOKIE_HEADER_NAME; - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterCookiesFromHeader( - httpRequest.getHeaders(cookieName), - scopes.getOptions().getDataCollectionResolver().getCookies(), - additionalSecurityCookieNames))); - } else if (scopes.getOptions().isSendDefaultPii()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - httpRequest.getHeaders(cookieName), cookieName, additionalSecurityCookieNames))); - } + sentryRequest.setCookies( + toString( + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders(cookieName), + scopes.getOptions().getDataCollectionResolver().getCookies(), + additionalSecurityCookieNames))); return sentryRequest; } @@ -73,20 +66,13 @@ Map resolveHeadersMap( final @NotNull List additionalSecurityCookieNames) { final Map headersMap = new HashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured() - || scopes.getOptions().isSendDefaultPii() - || !HttpUtils.containsSensitiveHeader(headerName)) { - final @Nullable List filteredHeaders = - CookieUtils.filterOutSecurityCookiesFromHeader( - request.getHeaders(headerName), headerName, additionalSecurityCookieNames); - headersMap.put(headerName, toString(filteredHeaders)); - } - } - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); + final @Nullable List filteredHeaders = + CookieUtils.filterOutSecurityCookiesFromHeader( + request.getHeaders(headerName), headerName, additionalSecurityCookieNames); + headersMap.put(headerName, toString(filteredHeaders)); } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); } private List extractSecurityCookieNamesOrUseCached( diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentrySpanClientWebRequestFilter.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentrySpanClientWebRequestFilter.java index a29d0e0508a..2e7ddcb351e 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentrySpanClientWebRequestFilter.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/tracing/SentrySpanClientWebRequestFilter.java @@ -51,9 +51,7 @@ public SentrySpanClientWebRequestFilter(final @NotNull IScopes scopes) { final @NotNull String method = request.method().name(); span.setDescription(method + " " + urlDetails.getUrlOrFallback()); span.setData(SpanDataConvention.HTTP_METHOD_KEY, method.toUpperCase(Locale.ROOT)); - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - urlDetails.applyToSpan(span); - } + urlDetails.applyToSpan(span); final @NotNull ClientRequest modifiedRequest = maybeAddTracingHeaders(request, span); diff --git a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryRequestResolver.java b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryRequestResolver.java index f188f7ec5a4..90641010615 100644 --- a/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryRequestResolver.java +++ b/sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/webflux/SentryRequestResolver.java @@ -40,19 +40,12 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { sentryRequest.setHeaders(resolveHeadersMap(httpRequest.getHeaders())); final @NotNull String headerName = CookieUtils.COOKIE_HEADER_NAME; - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterCookiesFromHeader( - httpRequest.getHeaders().get(headerName), - scopes.getOptions().getDataCollectionResolver().getCookies(), - Collections.emptyList()))); - } else if (scopes.getOptions().isSendDefaultPii()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - httpRequest.getHeaders().get(headerName), headerName, Collections.emptyList()))); - } + sentryRequest.setCookies( + toString( + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders().get(headerName), + scopes.getOptions().getDataCollectionResolver().getCookies(), + Collections.emptyList()))); return sentryRequest; } @@ -60,22 +53,15 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { Map resolveHeadersMap(final HttpHeaders request) { final Map headersMap = new HashMap<>(); for (Map.Entry> entry : request.entrySet()) { - String headerName = entry.getKey(); - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured() - || scopes.getOptions().isSendDefaultPii() - || !HttpUtils.containsSensitiveHeader(headerName)) { - headersMap.put( - headerName, - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - entry.getValue(), headerName, Collections.emptyList()))); - } - } - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); + final String headerName = entry.getKey(); + headersMap.put( + headerName, + toString( + CookieUtils.filterOutSecurityCookiesFromHeader( + entry.getValue(), headerName, Collections.emptyList()))); } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); } private static @Nullable String toString(final @Nullable List enumeration) { diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/EnableSentryTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/EnableSentryTest.kt index 879f30d558b..3c2234db9e6 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/EnableSentryTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/EnableSentryTest.kt @@ -21,23 +21,17 @@ class EnableSentryTest { ApplicationContextRunner().withConfiguration(UserConfigurations.of(AppConfig::class.java)) @Test - fun `sets properties from environment on SentryOptions`() { - ApplicationContextRunner() - .withConfiguration(UserConfigurations.of(AppConfigWithDefaultSendPii::class.java)) - .run { - assertThat(it).hasSingleBean(SentryOptions::class.java) - val options = it.getBean(SentryOptions::class.java) - assertThat(options.dsn).isEqualTo("http://key@localhost/proj") - assertThat(options.isSendDefaultPii).isTrue() - } + fun `sets dsn from annotation on SentryOptions`() { + contextRunner.run { + assertThat(it).hasSingleBean(SentryOptions::class.java) + assertThat(it.getBean(SentryOptions::class.java).dsn).isEqualTo("http://key@localhost/proj") + } ApplicationContextRunner() .withConfiguration(UserConfigurations.of(AppConfigWithEmptyDsn::class.java)) .run { assertThat(it).hasSingleBean(SentryOptions::class.java) - val options = it.getBean(SentryOptions::class.java) - assertThat(options.dsn).isEmpty() - assertThat(options.isSendDefaultPii).isFalse() + assertThat(it.getBean(SentryOptions::class.java).dsn).isEmpty() } } @@ -181,9 +175,6 @@ class EnableSentryTest { @EnableSentry(dsn = "") class AppConfigWithEmptyDsn - @EnableSentry(dsn = "http://key@localhost/proj", sendDefaultPii = true) - class AppConfigWithDefaultSendPii - @EnableSentry(dsn = "http://key@localhost/proj", exceptionResolverOrder = Integer.MAX_VALUE) class AppConfigWithExceptionResolverOrderIntegerMaxValue diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/HttpServletRequestSentryUserProviderTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/HttpServletRequestSentryUserProviderTest.kt index f3cf07525a2..fa67c2d419b 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/HttpServletRequestSentryUserProviderTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/HttpServletRequestSentryUserProviderTest.kt @@ -19,9 +19,7 @@ class HttpServletRequestSentryUserProviderTest { request.addHeader("X-FORWARDED-FOR", "192.168.0.1,192.168.0.2") RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = SentryOptions() - options.isSendDefaultPii = true - val userProvider = HttpServletRequestSentryUserProvider(options) + val userProvider = HttpServletRequestSentryUserProvider(SentryOptions()) val result = userProvider.provideUser() assertNotNull(result) @@ -36,9 +34,7 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = SentryOptions() - options.isSendDefaultPii = true - val userProvider = HttpServletRequestSentryUserProvider(options) + val userProvider = HttpServletRequestSentryUserProvider(SentryOptions()) val result = userProvider.provideUser() assertNotNull(result) @@ -53,11 +49,7 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = - SentryOptions().apply { - isSendDefaultPii = true - dataCollection.setUserInfo(false) - } + val options = SentryOptions().apply { dataCollection.setUserInfo(false) } val result = HttpServletRequestSentryUserProvider(options).provideUser() assertNull(result) @@ -71,30 +63,10 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = - SentryOptions().apply { - isSendDefaultPii = false - dataCollection.setUserInfo(true) - } + val options = SentryOptions().apply { dataCollection.setUserInfo(true) } val result = HttpServletRequestSentryUserProvider(options).provideUser() assertNotNull(result) assertEquals("janesmith", result.username) } - - @Test - fun `when sendDefaultPii is set to false, does not attach user data Sentry Event`() { - val principal = mock() - whenever(principal.name).thenReturn("janesmith") - val request = MockHttpServletRequest() - request.userPrincipal = principal - RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - - val options = SentryOptions() - options.isSendDefaultPii = false - val userProvider = HttpServletRequestSentryUserProvider(options) - val result = userProvider.provideUser() - - assertNull(result) - } } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt index 2adf22799f0..0c95503f135 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentrySpringFilterTest.kt @@ -22,7 +22,6 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertNotNull -import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.test.fail import org.assertj.core.api.Assertions @@ -168,8 +167,8 @@ class SentrySpringFilterTest { } @Test - fun `when sendDefaultPii is set to true, attaches filtered cookies to Scope request`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = true } + fun `attaches filtered cookies to Scope request by default`() { + val sentryOptions = SentryOptions() val listener = fixture.getSut( @@ -187,28 +186,10 @@ class SentrySpringFilterTest { val expectedCookieString = "name=value; JSESSIONID=[Filtered]; mysessioncookiename=[Filtered],name2=value2; SID=[Filtered]" assertEquals(expectedCookieString, it.cookies) - assertEquals(expectedCookieString, it.headers!!["Cookie"]) + assertEquals("[Filtered]", it.headers!!["Cookie"]) } } - @Test - fun `when sendDefaultPii is set to false, does not attach cookies to Scope request`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = false } - - val listener = - fixture.getSut( - request = - MockMvcRequestBuilders.get(URI.create("http://example.com?param1=xyz")) - .header("Cookie", "name=value") - .buildRequest(MockServletContext()), - options = sentryOptions, - ) - - listener.doFilter(fixture.request, fixture.response, fixture.chain) - - assertNotNull(fixture.scope.request) { assertNull(it.cookies) } - } - @Test fun `data collection filters request headers`() { val sentryOptions = @@ -234,8 +215,8 @@ class SentrySpringFilterTest { } @Test - fun `when sendDefaultPii is set to false, does not attach sensitive headers`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = false } + fun `filters sensitive headers by default`() { + val sentryOptions = SentryOptions() val listener = fixture.getSut( @@ -244,7 +225,6 @@ class SentrySpringFilterTest { .header("some-header", "some-header value") .header("X-FORWARDED-FOR", "192.168.0.1") .header("authorization", "Token") - .header("Authorization", "Token") .header("Cookie", "some cookies") .buildRequest(MockServletContext()), options = sentryOptions, @@ -254,10 +234,9 @@ class SentrySpringFilterTest { assertNotNull(fixture.scope.request) { request -> assertNotNull(request.headers) { - assertFalse(it.containsKey("X-FORWARDED-FOR")) - assertFalse(it.containsKey("Authorization")) - assertFalse(it.containsKey("authorization")) - assertFalse(it.containsKey("Cookie")) + assertEquals("192.168.0.1", it["X-FORWARDED-FOR"]) + assertEquals("[Filtered]", it["authorization"]) + assertEquals("[Filtered]", it["Cookie"]) assertTrue(it.containsKey("some-header")) } } @@ -266,7 +245,6 @@ class SentrySpringFilterTest { @Test fun `caches request depending on the maxRequestBodySize value and request body length`() { data class TestParams( - val sendDefaultPii: Boolean = true, val maxRequestBodySize: SentryOptions.RequestSize, val body: String, val contentType: String = "application/json", @@ -276,12 +254,6 @@ class SentrySpringFilterTest { val params = listOf( TestParams(maxRequestBodySize = NONE, body = "xxx", expectedToBeCached = false), - TestParams( - maxRequestBodySize = SMALL, - body = "xxx", - expectedToBeCached = false, - sendDefaultPii = false, - ), TestParams(maxRequestBodySize = SMALL, body = "xxx", expectedToBeCached = true), TestParams( maxRequestBodySize = SMALL, @@ -318,11 +290,7 @@ class SentrySpringFilterTest { params.forEach { param -> try { val fixture = Fixture() - val sentryOptions = - SentryOptions().apply { - maxRequestBodySize = param.maxRequestBodySize - isSendDefaultPii = param.sendDefaultPii - } + val sentryOptions = SentryOptions().apply { maxRequestBodySize = param.maxRequestBodySize } val listener = fixture.getSut( @@ -349,10 +317,9 @@ class SentrySpringFilterTest { } @Test - fun `data collection can enable request body when sendDefaultPii is false`() { + fun `data collection can enable request body`() { val options = SentryOptions().apply { - isSendDefaultPii = false maxRequestBodySize = SMALL dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_REQUEST) } @@ -372,10 +339,9 @@ class SentrySpringFilterTest { } @Test - fun `data collection can disable request body when sendDefaultPii is true`() { + fun `data collection can disable request body`() { val options = SentryOptions().apply { - isSendDefaultPii = true maxRequestBodySize = SMALL dataCollection.httpBodies = emptySet() } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryUserFilterTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryUserFilterTest.kt index d54772071a7..d024c1afcb1 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryUserFilterTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryUserFilterTest.kt @@ -25,15 +25,10 @@ class SentryUserFilterTest { val chain = mock() fun getSut( - isSendDefaultPii: Boolean = false, userInfo: Boolean? = null, userProviders: List, ): SentryUserFilter { - val options = - SentryOptions().apply { - this.isSendDefaultPii = isSendDefaultPii - userInfo?.let { dataCollection.setUserInfo(it) } - } + val options = SentryOptions().apply { userInfo?.let { dataCollection.setUserInfo(it) } } whenever(scopes.options).thenReturn(options) return SentryUserFilter(scopes, userProviders) } @@ -101,10 +96,9 @@ class SentryUserFilterTest { } @Test - fun `when isSendDefaultPii is true and user is set with custom ip address, user ip is unchanged`() { + fun `when user is set with custom ip address, user ip is unchanged`() { val filter = fixture.getSut( - isSendDefaultPii = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "192.168.0.1" } }), ) @@ -114,10 +108,9 @@ class SentryUserFilterTest { } @Test - fun `when isSendDefaultPii is true and user is set with {{auto}} ip address, user ip is set to null`() { + fun `when user is set with {{auto}} ip address, user ip is set to null`() { val filter = fixture.getSut( - isSendDefaultPii = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) @@ -130,7 +123,6 @@ class SentryUserFilterTest { fun `when user info is disabled, preserves auto ip from a custom provider`() { val filter = fixture.getSut( - isSendDefaultPii = true, userInfo = false, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) @@ -144,7 +136,6 @@ class SentryUserFilterTest { fun `when user info is enabled, removes auto ip from a custom provider`() { val filter = fixture.getSut( - isSendDefaultPii = false, userInfo = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SpringSecuritySentryUserProviderTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SpringSecuritySentryUserProviderTest.kt index 8bd503c3180..7e548a4287f 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SpringSecuritySentryUserProviderTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SpringSecuritySentryUserProviderTest.kt @@ -14,15 +14,10 @@ import org.springframework.security.core.context.SecurityContextHolder class SpringSecuritySentryUserProviderTest { class Fixture { fun getSut( - isSendDefaultPii: Boolean = true, username: String? = null, userInfo: Boolean? = null, ): SpringSecuritySentryUserProvider { - val options = - SentryOptions().apply { - this.isSendDefaultPii = isSendDefaultPii - userInfo?.let { dataCollection.setUserInfo(it) } - } + val options = SentryOptions().apply { userInfo?.let { dataCollection.setUserInfo(it) } } val securityContext = mock() if (username != null) { val authentication = mock() @@ -39,36 +34,29 @@ class SpringSecuritySentryUserProviderTest { private val fixture = Fixture() @Test - fun `when send default pii is set to true, returns user with username set`() { - val provider = fixture.getSut(true, "name") + fun `returns user with username set by default`() { + val provider = fixture.getSut(username = "name") val user = provider.provideUser() assertNotNull(user) { assertEquals("name", it.username) } } @Test - fun `when send default pii is set to false, returns null`() { - val provider = fixture.getSut(false) - val user = provider.provideUser() - assertNull(user) - } - - @Test - fun `when user info is disabled, returns null even if sendDefaultPii is true`() { - val provider = fixture.getSut(isSendDefaultPii = true, username = "name", userInfo = false) + fun `when user info is disabled, returns null`() { + val provider = fixture.getSut(username = "name", userInfo = false) assertNull(provider.provideUser()) } @Test - fun `when user info is enabled, returns user even if sendDefaultPii is false`() { - val provider = fixture.getSut(isSendDefaultPii = false, username = "name", userInfo = true) + fun `when user info is enabled, returns user`() { + val provider = fixture.getSut(username = "name", userInfo = true) assertNotNull(provider.provideUser()) { assertEquals("name", it.username) } } @Test - fun `when send default pii is set to true and security context is not set, returns null`() { - val provider = fixture.getSut(true) + fun `when security context is not set, returns null`() { + val provider = fixture.getSut() val user = provider.provideUser() assertNull(user) } diff --git a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/mvc/SentrySpringIntegrationTest.kt b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/mvc/SentrySpringIntegrationTest.kt index f1837a08c1f..5e6f098f8cb 100644 --- a/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/mvc/SentrySpringIntegrationTest.kt +++ b/sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/mvc/SentrySpringIntegrationTest.kt @@ -388,7 +388,6 @@ class SentrySpringIntegrationTest { @SpringBootApplication @EnableSentry( dsn = "http://key@localhost/proj", - sendDefaultPii = true, maxRequestBodySize = SentryOptions.RequestSize.MEDIUM, ) @Import(SentryTracingConfiguration::class, SentryCaptureExceptionParameterConfiguration::class) diff --git a/sentry-spring/api/sentry-spring.api b/sentry-spring/api/sentry-spring.api index 33f383a4025..ceccb957075 100644 --- a/sentry-spring/api/sentry-spring.api +++ b/sentry-spring/api/sentry-spring.api @@ -13,7 +13,6 @@ public abstract interface annotation class io/sentry/spring/EnableSentry : java/ public abstract fun dsn ()Ljava/lang/String; public abstract fun exceptionResolverOrder ()I public abstract fun maxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize; - public abstract fun sendDefaultPii ()Z } public final class io/sentry/spring/HttpServletRequestSentryUserProvider : io/sentry/spring/SentryUserProvider { diff --git a/sentry-spring/src/integrationTest/kotlin/io/sentry/spring/integrationtest/IntegrationTestApplication.kt b/sentry-spring/src/integrationTest/kotlin/io/sentry/spring/integrationtest/IntegrationTestApplication.kt index f51d475470c..63ec8196fb2 100644 --- a/sentry-spring/src/integrationTest/kotlin/io/sentry/spring/integrationtest/IntegrationTestApplication.kt +++ b/sentry-spring/src/integrationTest/kotlin/io/sentry/spring/integrationtest/IntegrationTestApplication.kt @@ -32,7 +32,7 @@ class AppInitializer : AbstractAnnotationConfigDispatcherServletInitializer() { // The DSN and the traces path come from system properties, and the other options from // sentry.properties, all of which Sentry reads as external configuration. -@Configuration @EnableSentry(dsn = "", sendDefaultPii = true) open class AppConfig +@Configuration @EnableSentry(dsn = "") open class AppConfig // Declares the controllers rather than scanning for them, which would also pick up AppConfig and // initialize Sentry a second time in the servlet's context. diff --git a/sentry-spring/src/main/java/io/sentry/spring/EnableSentry.java b/sentry-spring/src/main/java/io/sentry/spring/EnableSentry.java index 055afd34846..61c683e706f 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/EnableSentry.java +++ b/sentry-spring/src/main/java/io/sentry/spring/EnableSentry.java @@ -30,13 +30,6 @@ */ String dsn() default ""; - /** - * Whether to send personal identifiable information along with events. - * - * @return true if send default PII or false otherwise. - */ - boolean sendDefaultPii() default false; - /** * Determines whether all web exceptions are reported or only uncaught exceptions. * diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryHubRegistrar.java b/sentry-spring/src/main/java/io/sentry/spring/SentryHubRegistrar.java index 14a6776e3ee..c515d87970e 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryHubRegistrar.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryHubRegistrar.java @@ -54,9 +54,6 @@ private void registerSentryOptions( builder.addPropertyValue("sdkVersion", createSdkVersion()); builder.addPropertyValue("initPriority", InitPriority.LOW); addPackageAndIntegrationInfo(); - if (annotationAttributes.containsKey("sendDefaultPii")) { - builder.addPropertyValue("sendDefaultPii", annotationAttributes.getBoolean("sendDefaultPii")); - } if (annotationAttributes.containsKey("maxRequestBodySize")) { builder.addPropertyValue( "maxRequestBodySize", annotationAttributes.get("maxRequestBodySize")); diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryRequestResolver.java b/sentry-spring/src/main/java/io/sentry/spring/SentryRequestResolver.java index 1c8ec52ac88..28793fc0937 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryRequestResolver.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryRequestResolver.java @@ -51,19 +51,12 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { sentryRequest.setHeaders(resolveHeadersMap(httpRequest, additionalSecurityCookieNames)); final @NotNull String cookieName = CookieUtils.COOKIE_HEADER_NAME; - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterCookiesFromHeader( - httpRequest.getHeaders(cookieName), - scopes.getOptions().getDataCollectionResolver().getCookies(), - additionalSecurityCookieNames))); - } else if (scopes.getOptions().isSendDefaultPii()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - httpRequest.getHeaders(cookieName), cookieName, additionalSecurityCookieNames))); - } + sentryRequest.setCookies( + toString( + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders(cookieName), + scopes.getOptions().getDataCollectionResolver().getCookies(), + additionalSecurityCookieNames))); return sentryRequest; } @@ -73,20 +66,13 @@ Map resolveHeadersMap( final @NotNull List additionalSecurityCookieNames) { final Map headersMap = new HashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured() - || scopes.getOptions().isSendDefaultPii() - || !HttpUtils.containsSensitiveHeader(headerName)) { - final @Nullable List filteredHeaders = - CookieUtils.filterOutSecurityCookiesFromHeader( - request.getHeaders(headerName), headerName, additionalSecurityCookieNames); - headersMap.put(headerName, toString(filteredHeaders)); - } - } - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); + final @Nullable List filteredHeaders = + CookieUtils.filterOutSecurityCookiesFromHeader( + request.getHeaders(headerName), headerName, additionalSecurityCookieNames); + headersMap.put(headerName, toString(filteredHeaders)); } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); } private List extractSecurityCookieNamesOrUseCached( diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryRequestResolver.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryRequestResolver.java index 321f2a05d8d..44dd8bc11ce 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryRequestResolver.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryRequestResolver.java @@ -40,19 +40,12 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { sentryRequest.setHeaders(resolveHeadersMap(httpRequest.getHeaders())); final @NotNull String headerName = CookieUtils.COOKIE_HEADER_NAME; - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterCookiesFromHeader( - httpRequest.getHeaders().get(headerName), - scopes.getOptions().getDataCollectionResolver().getCookies(), - Collections.emptyList()))); - } else if (scopes.getOptions().isSendDefaultPii()) { - sentryRequest.setCookies( - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - httpRequest.getHeaders().get(headerName), headerName, Collections.emptyList()))); - } + sentryRequest.setCookies( + toString( + CookieUtils.filterCookiesFromHeader( + httpRequest.getHeaders().get(headerName), + scopes.getOptions().getDataCollectionResolver().getCookies(), + Collections.emptyList()))); return sentryRequest; } @@ -60,22 +53,15 @@ public SentryRequestResolver(final @NotNull IScopes scopes) { Map resolveHeadersMap(final HttpHeaders request) { final Map headersMap = new HashMap<>(); for (Map.Entry> entry : request.entrySet()) { - String headerName = entry.getKey(); - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured() - || scopes.getOptions().isSendDefaultPii() - || !HttpUtils.containsSensitiveHeader(headerName)) { - headersMap.put( - headerName, - toString( - CookieUtils.filterOutSecurityCookiesFromHeader( - entry.getValue(), headerName, Collections.emptyList()))); - } - } - if (scopes.getOptions().getDataCollectionResolver().isDataCollectionConfigured()) { - return HttpUtils.filterHeaders( - headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); + final String headerName = entry.getKey(); + headersMap.put( + headerName, + toString( + CookieUtils.filterOutSecurityCookiesFromHeader( + entry.getValue(), headerName, Collections.emptyList()))); } - return headersMap; + return HttpUtils.filterHeaders( + headersMap, scopes.getOptions().getDataCollectionResolver().getHttpRequestHeaders()); } private static @Nullable String toString(final @Nullable List enumeration) { diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/EnableSentryTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/EnableSentryTest.kt index a54799d89d6..298bfc9e58b 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/EnableSentryTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/EnableSentryTest.kt @@ -21,23 +21,17 @@ class EnableSentryTest { ApplicationContextRunner().withConfiguration(UserConfigurations.of(AppConfig::class.java)) @Test - fun `sets properties from environment on SentryOptions`() { - ApplicationContextRunner() - .withConfiguration(UserConfigurations.of(AppConfigWithDefaultSendPii::class.java)) - .run { - assertThat(it).hasSingleBean(SentryOptions::class.java) - val options = it.getBean(SentryOptions::class.java) - assertThat(options.dsn).isEqualTo("http://key@localhost/proj") - assertThat(options.isSendDefaultPii).isTrue() - } + fun `sets dsn from annotation on SentryOptions`() { + contextRunner.run { + assertThat(it).hasSingleBean(SentryOptions::class.java) + assertThat(it.getBean(SentryOptions::class.java).dsn).isEqualTo("http://key@localhost/proj") + } ApplicationContextRunner() .withConfiguration(UserConfigurations.of(AppConfigWithEmptyDsn::class.java)) .run { assertThat(it).hasSingleBean(SentryOptions::class.java) - val options = it.getBean(SentryOptions::class.java) - assertThat(options.dsn).isEmpty() - assertThat(options.isSendDefaultPii).isFalse() + assertThat(it.getBean(SentryOptions::class.java).dsn).isEmpty() } } @@ -181,9 +175,6 @@ class EnableSentryTest { @EnableSentry(dsn = "") class AppConfigWithEmptyDsn - @EnableSentry(dsn = "http://key@localhost/proj", sendDefaultPii = true) - class AppConfigWithDefaultSendPii - @EnableSentry(dsn = "http://key@localhost/proj", exceptionResolverOrder = Integer.MAX_VALUE) class AppConfigWithExceptionResolverOrderIntegerMaxValue diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/HttpServletRequestSentryUserProviderTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/HttpServletRequestSentryUserProviderTest.kt index 3f3cc08bdcd..d9f4e05e8f1 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/HttpServletRequestSentryUserProviderTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/HttpServletRequestSentryUserProviderTest.kt @@ -19,9 +19,7 @@ class HttpServletRequestSentryUserProviderTest { request.addHeader("X-FORWARDED-FOR", "192.168.0.1,192.168.0.2") RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = SentryOptions() - options.isSendDefaultPii = true - val userProvider = HttpServletRequestSentryUserProvider(options) + val userProvider = HttpServletRequestSentryUserProvider(SentryOptions()) val result = userProvider.provideUser() assertNotNull(result) @@ -36,9 +34,7 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = SentryOptions() - options.isSendDefaultPii = true - val userProvider = HttpServletRequestSentryUserProvider(options) + val userProvider = HttpServletRequestSentryUserProvider(SentryOptions()) val result = userProvider.provideUser() assertNotNull(result) @@ -53,11 +49,7 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = - SentryOptions().apply { - isSendDefaultPii = true - dataCollection.setUserInfo(false) - } + val options = SentryOptions().apply { dataCollection.setUserInfo(false) } val result = HttpServletRequestSentryUserProvider(options).provideUser() assertNull(result) @@ -71,30 +63,10 @@ class HttpServletRequestSentryUserProviderTest { request.userPrincipal = principal RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - val options = - SentryOptions().apply { - isSendDefaultPii = false - dataCollection.setUserInfo(true) - } + val options = SentryOptions().apply { dataCollection.setUserInfo(true) } val result = HttpServletRequestSentryUserProvider(options).provideUser() assertNotNull(result) assertEquals("janesmith", result.username) } - - @Test - fun `when sendDefaultPii is set to false, does not attach user data Sentry Event`() { - val principal = mock() - whenever(principal.name).thenReturn("janesmith") - val request = MockHttpServletRequest() - request.userPrincipal = principal - RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) - - val options = SentryOptions() - options.isSendDefaultPii = false - val userProvider = HttpServletRequestSentryUserProvider(options) - val result = userProvider.provideUser() - - assertNull(result) - } } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt index c38da356b7f..cd8599d7299 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt @@ -168,8 +168,8 @@ class SentrySpringFilterTest { } @Test - fun `when sendDefaultPii is set to true, attaches filtered cookies to Scope request`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = true } + fun `attaches filtered cookies to Scope request by default`() { + val sentryOptions = SentryOptions() val listener = fixture.getSut( @@ -187,33 +187,14 @@ class SentrySpringFilterTest { val expectedCookieString = "name=value; JSESSIONID=[Filtered]; mysessioncookiename=[Filtered],name2=value2; SID=[Filtered]" assertEquals(expectedCookieString, it.cookies) - assertEquals(expectedCookieString, it.headers!!["Cookie"]) + assertEquals("[Filtered]", it.headers!!["Cookie"]) } } @Test - fun `when sendDefaultPii is set to false, does not attach cookies to Scope request`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = false } - - val listener = - fixture.getSut( - request = - MockMvcRequestBuilders.get(URI.create("http://example.com?param1=xyz")) - .header("Cookie", "name=value") - .buildRequest(MockServletContext()), - options = sentryOptions, - ) - - listener.doFilter(fixture.request, fixture.response, fixture.chain) - - assertNotNull(fixture.scope.request) { assertNull(it.cookies) } - } - - @Test - fun `data collection filters cookies and ignores sendDefaultPii`() { + fun `data collection filters cookies`() { val sentryOptions = SentryOptions().apply { - isSendDefaultPii = false dataCollection.cookies = KeyValueCollectionBehavior.denyList("customer") } @@ -240,10 +221,7 @@ class SentrySpringFilterTest { @Test fun `data collection can disable cookies`() { val sentryOptions = - SentryOptions().apply { - isSendDefaultPii = true - dataCollection.cookies = KeyValueCollectionBehavior.off() - } + SentryOptions().apply { dataCollection.cookies = KeyValueCollectionBehavior.off() } val listener = fixture.getSut( request = @@ -283,8 +261,8 @@ class SentrySpringFilterTest { } @Test - fun `when sendDefaultPii is set to false, does not attach sensitive headers`() { - val sentryOptions = SentryOptions().apply { isSendDefaultPii = false } + fun `filters sensitive headers by default`() { + val sentryOptions = SentryOptions() val listener = fixture.getSut( @@ -293,7 +271,6 @@ class SentrySpringFilterTest { .header("some-header", "some-header value") .header("X-FORWARDED-FOR", "192.168.0.1") .header("authorization", "Token") - .header("Authorization", "Token") .header("Cookie", "some cookies") .buildRequest(MockServletContext()), options = sentryOptions, @@ -303,10 +280,9 @@ class SentrySpringFilterTest { assertNotNull(fixture.scope.request) { request -> assertNotNull(request.headers) { - assertFalse(it.containsKey("X-FORWARDED-FOR")) - assertFalse(it.containsKey("Authorization")) - assertFalse(it.containsKey("authorization")) - assertFalse(it.containsKey("Cookie")) + assertEquals("192.168.0.1", it["X-FORWARDED-FOR"]) + assertEquals("[Filtered]", it["authorization"]) + assertEquals("[Filtered]", it["Cookie"]) assertTrue(it.containsKey("some-header")) } } @@ -315,7 +291,6 @@ class SentrySpringFilterTest { @Test fun `caches request depending on the maxRequestBodySize value and request body length`() { data class TestParams( - val sendDefaultPii: Boolean = true, val maxRequestBodySize: SentryOptions.RequestSize, val body: String, val contentType: String = "application/json", @@ -325,12 +300,6 @@ class SentrySpringFilterTest { val params = listOf( TestParams(maxRequestBodySize = NONE, body = "xxx", expectedToBeCached = false), - TestParams( - maxRequestBodySize = SMALL, - body = "xxx", - expectedToBeCached = false, - sendDefaultPii = false, - ), TestParams(maxRequestBodySize = SMALL, body = "xxx", expectedToBeCached = true), TestParams( maxRequestBodySize = SMALL, @@ -367,11 +336,7 @@ class SentrySpringFilterTest { params.forEach { param -> try { val fixture = Fixture() - val sentryOptions = - SentryOptions().apply { - maxRequestBodySize = param.maxRequestBodySize - isSendDefaultPii = param.sendDefaultPii - } + val sentryOptions = SentryOptions().apply { maxRequestBodySize = param.maxRequestBodySize } val listener = fixture.getSut( @@ -398,10 +363,9 @@ class SentrySpringFilterTest { } @Test - fun `data collection can enable request body when sendDefaultPii is false`() { + fun `data collection can enable request body`() { val options = SentryOptions().apply { - isSendDefaultPii = false maxRequestBodySize = SMALL dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_REQUEST) } @@ -421,10 +385,9 @@ class SentrySpringFilterTest { } @Test - fun `data collection can disable request body when sendDefaultPii is true`() { + fun `data collection can disable request body`() { val options = SentryOptions().apply { - isSendDefaultPii = true maxRequestBodySize = SMALL dataCollection.httpBodies = emptySet() } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryUserFilterTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryUserFilterTest.kt index 21730ea451f..004062cf566 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryUserFilterTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryUserFilterTest.kt @@ -25,15 +25,10 @@ class SentryUserFilterTest { val chain = mock() fun getSut( - isSendDefaultPii: Boolean = false, userInfo: Boolean? = null, userProviders: List, ): SentryUserFilter { - val options = - SentryOptions().apply { - this.isSendDefaultPii = isSendDefaultPii - userInfo?.let { dataCollection.setUserInfo(it) } - } + val options = SentryOptions().apply { userInfo?.let { dataCollection.setUserInfo(it) } } whenever(scopes.options).thenReturn(options) return SentryUserFilter(scopes, userProviders) } @@ -101,10 +96,9 @@ class SentryUserFilterTest { } @Test - fun `when isSendDefaultPii is true and user is set with custom ip address, user ip is unchanged`() { + fun `when user is set with custom ip address, user ip is unchanged`() { val filter = fixture.getSut( - isSendDefaultPii = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "192.168.0.1" } }), ) @@ -114,10 +108,9 @@ class SentryUserFilterTest { } @Test - fun `when isSendDefaultPii is true and user is set with {{auto}} ip address, user ip is set to null`() { + fun `when user is set with {{auto}} ip address, user ip is set to null`() { val filter = fixture.getSut( - isSendDefaultPii = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) @@ -130,7 +123,6 @@ class SentryUserFilterTest { fun `when user info is disabled, preserves auto ip from a custom provider`() { val filter = fixture.getSut( - isSendDefaultPii = true, userInfo = false, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) @@ -144,7 +136,6 @@ class SentryUserFilterTest { fun `when user info is enabled, removes auto ip from a custom provider`() { val filter = fixture.getSut( - isSendDefaultPii = false, userInfo = true, userProviders = listOf(SentryUserProvider { User().apply { ipAddress = "{{auto}}" } }), ) diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SpringSecuritySentryUserProviderTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SpringSecuritySentryUserProviderTest.kt index 7ba3ea787e9..ce65f277860 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SpringSecuritySentryUserProviderTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SpringSecuritySentryUserProviderTest.kt @@ -14,15 +14,10 @@ import org.springframework.security.core.context.SecurityContextHolder class SpringSecuritySentryUserProviderTest { class Fixture { fun getSut( - isSendDefaultPii: Boolean = true, username: String? = null, userInfo: Boolean? = null, ): SpringSecuritySentryUserProvider { - val options = - SentryOptions().apply { - this.isSendDefaultPii = isSendDefaultPii - userInfo?.let { dataCollection.setUserInfo(it) } - } + val options = SentryOptions().apply { userInfo?.let { dataCollection.setUserInfo(it) } } val securityContext = mock() if (username != null) { val authentication = mock() @@ -39,36 +34,29 @@ class SpringSecuritySentryUserProviderTest { private val fixture = Fixture() @Test - fun `when send default pii is set to true, returns user with username set`() { - val provider = fixture.getSut(true, "name") + fun `returns user with username set by default`() { + val provider = fixture.getSut(username = "name") val user = provider.provideUser() assertNotNull(user) { assertEquals("name", it.username) } } @Test - fun `when send default pii is set to false, returns null`() { - val provider = fixture.getSut(false) - val user = provider.provideUser() - assertNull(user) - } - - @Test - fun `when user info is disabled, returns null even if sendDefaultPii is true`() { - val provider = fixture.getSut(isSendDefaultPii = true, username = "name", userInfo = false) + fun `when user info is disabled, returns null`() { + val provider = fixture.getSut(username = "name", userInfo = false) assertNull(provider.provideUser()) } @Test - fun `when user info is enabled, returns user even if sendDefaultPii is false`() { - val provider = fixture.getSut(isSendDefaultPii = false, username = "name", userInfo = true) + fun `when user info is enabled, returns user`() { + val provider = fixture.getSut(username = "name", userInfo = true) assertNotNull(provider.provideUser()) { assertEquals("name", it.username) } } @Test - fun `when send default pii is set to true and security context is not set, returns null`() { - val provider = fixture.getSut(true) + fun `when security context is not set, returns null`() { + val provider = fixture.getSut() val user = provider.provideUser() assertNull(user) } diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/mvc/SentrySpringIntegrationTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/mvc/SentrySpringIntegrationTest.kt index 26afd5811bf..4aacf6941c8 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/mvc/SentrySpringIntegrationTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/mvc/SentrySpringIntegrationTest.kt @@ -388,7 +388,6 @@ class SentrySpringIntegrationTest { @SpringBootApplication @EnableSentry( dsn = "http://key@localhost/proj", - sendDefaultPii = true, maxRequestBodySize = SentryOptions.RequestSize.MEDIUM, ) @Import(SentryTracingConfiguration::class, SentryCaptureExceptionParameterConfiguration::class) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index ecba7bee503..52c3b091f79 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -389,7 +389,6 @@ public final class io/sentry/DataCategory : java/lang/Enum { public final class io/sentry/DataCollection { public fun ()V - public fun forceDataCollection ()V public fun getCookies ()Lio/sentry/KeyValueCollectionBehavior; public fun getDatabaseQueryData ()Ljava/lang/Boolean; public fun getFilePaths ()Ljava/lang/Boolean; @@ -428,20 +427,14 @@ public final class io/sentry/DataCollectionResolver { public fun getHttpRequestHeaders ()Lio/sentry/KeyValueCollectionBehavior; public fun getHttpResponseHeaders ()Lio/sentry/KeyValueCollectionBehavior; public fun getUrlQueryParams ()Lio/sentry/KeyValueCollectionBehavior; - public fun isDataCollectionConfigured ()Z public fun isDatabaseQueryData ()Z public fun isFilePaths ()Z public fun isGraphqlDocument ()Z - public fun isGraphqlDocumentWithLegacyAlways ()Z - public fun isGraphqlDocumentWithLegacyBodyGate ()Z public fun isGraphqlVariables ()Z - public fun isGraphqlVariablesWithLegacyAlways ()Z - public fun isGraphqlVariablesWithLegacyBodyGate ()Z public fun isIncomingRequestBody ()Z public fun isIncomingResponseBody ()Z public fun isOutgoingRequestBody ()Z public fun isOutgoingResponseBody ()Z - public fun isOutgoingResponseBodyWithLegacyBodyGate ()Z public fun isUserInfo ()Z } @@ -604,7 +597,6 @@ public final class io/sentry/ExternalOptions { public fun isEnabled ()Ljava/lang/Boolean; public fun isForceInit ()Ljava/lang/Boolean; public fun isGlobalHubMode ()Ljava/lang/Boolean; - public fun isSendDefaultPii ()Ljava/lang/Boolean; public fun isSendModules ()Ljava/lang/Boolean; public fun isStrictTraceContinuation ()Ljava/lang/Boolean; public fun setCaptureOpenTelemetryEvents (Ljava/lang/Boolean;)V @@ -642,7 +634,6 @@ public final class io/sentry/ExternalOptions { public fun setRelease (Ljava/lang/String;)V public fun setSampleRate (Ljava/lang/Double;)V public fun setSendClientReports (Ljava/lang/Boolean;)V - public fun setSendDefaultPii (Ljava/lang/Boolean;)V public fun setSendModules (Ljava/lang/Boolean;)V public fun setServerName (Ljava/lang/String;)V public fun setSessionFlushTimeoutMillis (Ljava/lang/Long;)V @@ -3679,7 +3670,6 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig { public fun isProfilingEnabled ()Z public fun isPropagateTraceparent ()Z public fun isSendClientReports ()Z - public fun isSendDefaultPii ()Z public fun isSendModules ()Z public fun isStartProfilerOnAppStart ()Z public fun isStrictTraceContinuation ()Z @@ -3790,7 +3780,6 @@ public class io/sentry/SentryOptions : io/sentry/transport/RateLimiterConfig { public fun setScopesStorageFactory (Lio/sentry/IScopesStorageFactory;)V public fun setSdkVersion (Lio/sentry/protocol/SdkVersion;)V public fun setSendClientReports (Z)V - public fun setSendDefaultPii (Z)V public fun setSendModules (Z)V public fun setSentryClientName (Ljava/lang/String;)V public fun setSerializer (Lio/sentry/ISerializer;)V @@ -7709,7 +7698,6 @@ public abstract interface class io/sentry/util/HintUtils$SentryNullableConsumer public final class io/sentry/util/HttpUtils { public fun ()V - public static fun containsSensitiveHeader (Ljava/lang/String;)Z public static fun filterHeaders (Ljava/util/Map;Lio/sentry/KeyValueCollectionBehavior;)Ljava/util/Map; public static fun filterQueryParams (Ljava/lang/String;Lio/sentry/KeyValueCollectionBehavior;)Ljava/lang/String; public static fun isHttpClientError (I)Z diff --git a/sentry/src/main/java/io/sentry/DataCollection.java b/sentry/src/main/java/io/sentry/DataCollection.java index e0a45e6aa58..9da4b9e598d 100644 --- a/sentry/src/main/java/io/sentry/DataCollection.java +++ b/sentry/src/main/java/io/sentry/DataCollection.java @@ -10,8 +10,6 @@ /** Configures data that the SDK collects automatically. */ public final class DataCollection { - // Forces Data Collection to be used even when no individual option has been configured. - private boolean forceDataCollection; private @Nullable Boolean userInfo; private @Nullable KeyValueCollectionBehavior cookies; private @Nullable KeyValueCollectionBehavior urlQueryParams; @@ -23,11 +21,6 @@ public final class DataCollection { public DataCollection() {} - /** Opts into the documented Data Collection defaults when no individual option is configured. */ - public void forceDataCollection() { - forceDataCollection = true; - } - public @Nullable Boolean getUserInfo() { return userInfo; } @@ -91,8 +84,7 @@ public void setFilePaths(final @Nullable Boolean filePaths) { @ApiStatus.Internal public boolean isExplicitlyConfigured() { - return forceDataCollection - || userInfo != null + return userInfo != null || cookies != null || urlQueryParams != null || httpBodies != null diff --git a/sentry/src/main/java/io/sentry/DataCollectionResolver.java b/sentry/src/main/java/io/sentry/DataCollectionResolver.java index 81ec4dd16b0..cffbff38004 100644 --- a/sentry/src/main/java/io/sentry/DataCollectionResolver.java +++ b/sentry/src/main/java/io/sentry/DataCollectionResolver.java @@ -6,7 +6,6 @@ import org.jetbrains.annotations.Nullable; /** Resolves effective Data Collection policies for SDK integrations. */ -@SuppressWarnings("deprecation") @ApiStatus.Internal public final class DataCollectionResolver { @@ -16,127 +15,70 @@ public final class DataCollectionResolver { this.options = options; } - public boolean isDataCollectionConfigured() { - return options.getDataCollection().isExplicitlyConfigured(); - } - public boolean isUserInfo() { - return explicitOrSendDefaultPii(options.getDataCollection().getUserInfo(), true); + return explicitOrDefault(options.getDataCollection().getUserInfo(), true); } public boolean isDatabaseQueryData() { - return explicitOrSendDefaultPii(options.getDataCollection().getDatabaseQueryData(), true); + return explicitOrDefault(options.getDataCollection().getDatabaseQueryData(), true); } public boolean isFilePaths() { - return explicitOrSendDefaultPii(options.getDataCollection().getFilePaths(), true); + return explicitOrDefault(options.getDataCollection().getFilePaths(), true); } public boolean isGraphqlDocument() { - return explicitOrSendDefaultPii(options.getDataCollection().getGraphql().getDocument(), true); - } - - public boolean isGraphqlDocumentWithLegacyBodyGate() { - return explicitOrDefault( - options.getDataCollection().getGraphql().getDocument(), true, isLegacyGraphqlBodyEnabled()); - } - - public boolean isGraphqlDocumentWithLegacyAlways() { - return explicitOrDefault(options.getDataCollection().getGraphql().getDocument(), true, true); + return explicitOrDefault(options.getDataCollection().getGraphql().getDocument(), true); } public boolean isGraphqlVariables() { - return explicitOrSendDefaultPii(options.getDataCollection().getGraphql().getVariables(), true); - } - - public boolean isGraphqlVariablesWithLegacyBodyGate() { - return explicitOrDefault( - options.getDataCollection().getGraphql().getVariables(), - true, - isLegacyGraphqlBodyEnabled()); - } - - public boolean isGraphqlVariablesWithLegacyAlways() { - return explicitOrDefault(options.getDataCollection().getGraphql().getVariables(), true, true); + return explicitOrDefault(options.getDataCollection().getGraphql().getVariables(), true); } public @NotNull KeyValueCollectionBehavior getCookies() { - final @NotNull DataCollection dataCollection = options.getDataCollection(); - final @Nullable KeyValueCollectionBehavior cookies = dataCollection.getCookies(); - - if (cookies != null) { - return cookies; - } - if (isDataCollectionConfigured()) { - return KeyValueCollectionBehavior.denyList(); - } - return options.isSendDefaultPii() - ? KeyValueCollectionBehavior.denyList() - : KeyValueCollectionBehavior.off(); + final @Nullable KeyValueCollectionBehavior cookies = options.getDataCollection().getCookies(); + return cookies != null ? cookies : KeyValueCollectionBehavior.denyList(); } public @NotNull KeyValueCollectionBehavior getUrlQueryParams() { - return explicitOrEmptyDenyList(options.getDataCollection().getUrlQueryParams()); + return explicitOrDefault(options.getDataCollection().getUrlQueryParams()); } public @NotNull KeyValueCollectionBehavior getHttpRequestHeaders() { - return explicitOrEmptyDenyList(options.getDataCollection().getHttpHeaders().getRequest()); + return explicitOrDefault(options.getDataCollection().getHttpHeaders().getRequest()); } public @NotNull KeyValueCollectionBehavior getHttpResponseHeaders() { - return explicitOrEmptyDenyList(options.getDataCollection().getHttpHeaders().getResponse()); + return explicitOrDefault(options.getDataCollection().getHttpHeaders().getResponse()); } public boolean isIncomingRequestBody() { - return isHttpBodyEnabled(HttpBodyType.INCOMING_REQUEST, options.isSendDefaultPii()); + return isHttpBodyEnabled(HttpBodyType.INCOMING_REQUEST); } public boolean isOutgoingRequestBody() { - return isHttpBodyEnabled(HttpBodyType.OUTGOING_REQUEST, true); + return isHttpBodyEnabled(HttpBodyType.OUTGOING_REQUEST); } public boolean isIncomingResponseBody() { - return isHttpBodyEnabled(HttpBodyType.INCOMING_RESPONSE, true); + return isHttpBodyEnabled(HttpBodyType.INCOMING_RESPONSE); } public boolean isOutgoingResponseBody() { - return isHttpBodyEnabled(HttpBodyType.OUTGOING_RESPONSE, options.isSendDefaultPii()); - } - - public boolean isOutgoingResponseBodyWithLegacyBodyGate() { - return isHttpBodyEnabled(HttpBodyType.OUTGOING_RESPONSE, isLegacyGraphqlBodyEnabled()); - } - - private boolean isLegacyGraphqlBodyEnabled() { - return options.isSendDefaultPii() - && !SentryOptions.RequestSize.NONE.equals(options.getMaxRequestBodySize()); - } - - private boolean explicitOrSendDefaultPii( - final @Nullable Boolean explicit, final boolean defaultValue) { - return explicitOrDefault(explicit, defaultValue, options.isSendDefaultPii()); + return isHttpBodyEnabled(HttpBodyType.OUTGOING_RESPONSE); } - private boolean explicitOrDefault( - final @Nullable Boolean explicit, final boolean defaultValue, final boolean legacyFallback) { - if (explicit != null) { - return explicit; - } - return isDataCollectionConfigured() ? defaultValue : legacyFallback; + private boolean explicitOrDefault(final @Nullable Boolean explicit, final boolean defaultValue) { + return explicit != null ? explicit : defaultValue; } - private @NotNull KeyValueCollectionBehavior explicitOrEmptyDenyList( + private @NotNull KeyValueCollectionBehavior explicitOrDefault( final @Nullable KeyValueCollectionBehavior explicit) { return explicit != null ? explicit : KeyValueCollectionBehavior.denyList(); } - private boolean isHttpBodyEnabled( - final @NotNull HttpBodyType bodyType, final boolean legacyFallback) { - final @NotNull DataCollection dataCollection = options.getDataCollection(); - final @Nullable Set httpBodies = dataCollection.getHttpBodies(); - if (httpBodies != null) { - return httpBodies.contains(bodyType); - } - return isDataCollectionConfigured() || legacyFallback; + private boolean isHttpBodyEnabled(final @NotNull HttpBodyType bodyType) { + final @Nullable Set httpBodies = options.getDataCollection().getHttpBodies(); + return httpBodies == null || httpBodies.contains(bodyType); } } diff --git a/sentry/src/main/java/io/sentry/ExternalOptions.java b/sentry/src/main/java/io/sentry/ExternalOptions.java index 0053e6a6442..d48d39f5810 100644 --- a/sentry/src/main/java/io/sentry/ExternalOptions.java +++ b/sentry/src/main/java/io/sentry/ExternalOptions.java @@ -54,7 +54,6 @@ public final class ExternalOptions { private @Nullable List traceIgnoreStatusCodes; private @Nullable Boolean sendModules; - private @Nullable Boolean sendDefaultPii; private @Nullable DataCollection dataCollection; private @Nullable Boolean enableBackpressureHandling; private @Nullable Boolean enableDatabaseTransactionTracing; @@ -159,7 +158,6 @@ public final class ExternalOptions { propertiesProvider.getBooleanProperty("enable-pretty-serialization-output")); options.setSendModules(propertiesProvider.getBooleanProperty("send-modules")); - options.setSendDefaultPii(propertiesProvider.getBooleanProperty("send-default-pii")); options.setDataCollection(parseDataCollection(propertiesProvider)); options.setIgnoredCheckIns(propertiesProvider.getListOrNull("ignored-checkins")); @@ -628,14 +626,6 @@ public void setSendModules(final @Nullable Boolean sendModules) { this.sendModules = sendModules; } - public @Nullable Boolean isSendDefaultPii() { - return sendDefaultPii; - } - - public void setSendDefaultPii(final @Nullable Boolean sendDefaultPii) { - this.sendDefaultPii = sendDefaultPii; - } - public @Nullable DataCollection getDataCollection() { return dataCollection; } diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 62b08dd106c..84723a9d581 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -358,9 +358,6 @@ public class SentryOptions implements RateLimiterConfig { /** SdkVersion object that contains the Sentry Client Name and its version */ private @Nullable SdkVersion sdkVersion; - /** whether to send personal identifiable information along with events */ - private boolean sendDefaultPii = false; - private @NotNull DataCollection dataCollection = new DataCollection(); private final @NotNull DataCollectionResolver dataCollectionResolver = @@ -1780,28 +1777,6 @@ public void setSdkVersion(final @Nullable SdkVersion sdkVersion) { this.sdkVersion = sdkVersion; } - /** - * Returns whether personally identifiable information is sent by default. - * - * @deprecated use {@link #getDataCollection()} instead. This option will be removed in 9.0. - */ - @ApiStatus.ScheduledForRemoval(inVersion = "9.0") - @Deprecated - public boolean isSendDefaultPii() { - return sendDefaultPii; - } - - /** - * Sets whether personally identifiable information is sent by default. - * - * @deprecated use {@link #getDataCollection()} instead. This option will be removed in 9.0. - */ - @ApiStatus.ScheduledForRemoval(inVersion = "9.0") - @Deprecated - public void setSendDefaultPii(boolean sendDefaultPii) { - this.sendDefaultPii = sendDefaultPii; - } - /** * Returns the configuration for data that the SDK collects automatically. * @@ -1815,9 +1790,8 @@ public void setSendDefaultPii(boolean sendDefaultPii) { /** * Replaces the configuration for data that the SDK collects automatically. * - *

This discards any Data Collection options already configured on this instance. To opt into - * the documented defaults while preserving them, call {@link - * DataCollection#forceDataCollection()} on the object returned by {@link #getDataCollection()}. + *

This discards any Data Collection options already configured on this instance. Options that + * are not explicitly configured use the documented defaults. */ public void setDataCollection(final @NotNull DataCollection dataCollection) { if (dataCollection != null) { @@ -3925,9 +3899,6 @@ public void merge(final @NotNull ExternalOptions options) { if (options.getMaxRequestBodySize() != null) { setMaxRequestBodySize(options.getMaxRequestBodySize()); } - if (options.isSendDefaultPii() != null) { - setSendDefaultPii(options.isSendDefaultPii()); - } if (options.getDataCollection() != null) { mergeDataCollection(options.getDataCollection()); } diff --git a/sentry/src/main/java/io/sentry/util/CookieUtils.java b/sentry/src/main/java/io/sentry/util/CookieUtils.java index 0b12acc1768..e50633a298d 100644 --- a/sentry/src/main/java/io/sentry/util/CookieUtils.java +++ b/sentry/src/main/java/io/sentry/util/CookieUtils.java @@ -14,7 +14,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -@SuppressWarnings("deprecation") @ApiStatus.Internal public final class CookieUtils { @@ -61,9 +60,6 @@ public final class CookieUtils { public static @Nullable String filterCookies( final @Nullable String cookies, final @NotNull SentryOptions options) { - if (!options.getDataCollectionResolver().isDataCollectionConfigured()) { - return options.isSendDefaultPii() ? cookies : null; - } return filterCookies(cookies, options.getDataCollectionResolver().getCookies(), null); } @@ -89,9 +85,6 @@ public final class CookieUtils { public static @Nullable String filterSetCookie( final @Nullable String cookie, final @NotNull SentryOptions options) { - if (!options.getDataCollectionResolver().isDataCollectionConfigured()) { - return options.isSendDefaultPii() ? cookie : null; - } return filterSetCookie(cookie, options.getDataCollectionResolver().getCookies()); } diff --git a/sentry/src/main/java/io/sentry/util/GraphqlUtils.java b/sentry/src/main/java/io/sentry/util/GraphqlUtils.java index faffc98afa5..26e51af85f0 100644 --- a/sentry/src/main/java/io/sentry/util/GraphqlUtils.java +++ b/sentry/src/main/java/io/sentry/util/GraphqlUtils.java @@ -23,8 +23,8 @@ private GraphqlUtils() {} public static @Nullable String filterRequestBody( final @NotNull String body, final @NotNull SentryOptions options) { final @NotNull DataCollectionResolver resolver = options.getDataCollectionResolver(); - final boolean includeDocument = resolver.isGraphqlDocumentWithLegacyAlways(); - final boolean includeVariables = resolver.isGraphqlVariablesWithLegacyAlways(); + final boolean includeDocument = resolver.isGraphqlDocument(); + final boolean includeVariables = resolver.isGraphqlVariables(); if (includeDocument && includeVariables) { return body; diff --git a/sentry/src/main/java/io/sentry/util/HttpUtils.java b/sentry/src/main/java/io/sentry/util/HttpUtils.java index 544cb18094e..d3a01980648 100644 --- a/sentry/src/main/java/io/sentry/util/HttpUtils.java +++ b/sentry/src/main/java/io/sentry/util/HttpUtils.java @@ -18,21 +18,6 @@ @ApiStatus.Internal public final class HttpUtils { - private static final List SENSITIVE_HEADERS = - Arrays.asList( - "X-FORWARDED-FOR", - "AUTHORIZATION", - "COOKIE", - "SET-COOKIE", - "X-API-KEY", - "X-REAL-IP", - "REMOTE-ADDR", - "FORWARDED", - "PROXY-AUTHORIZATION", - "X-CSRF-TOKEN", - "X-CSRFTOKEN", - "X-XSRF-TOKEN"); - // Keep these terms lowercase so sensitive-key checks only normalize the input key. private static final List SENSITIVE_DATA_KEYS = Arrays.asList( @@ -60,10 +45,6 @@ public final class HttpUtils { private static final HttpStatusCodeRange SEVER_ERROR_STATUS_CODES = new HttpStatusCodeRange(500, 599); - public static boolean containsSensitiveHeader(final @NotNull String header) { - return SENSITIVE_HEADERS.contains(header.toUpperCase(Locale.ROOT)); - } - public static @Nullable String filterQueryParams( final @Nullable String query, final @NotNull KeyValueCollectionBehavior behavior) { if (query == null || behavior.getMode() == KeyValueCollectionBehavior.Mode.OFF) { diff --git a/sentry/src/main/java/io/sentry/util/UrlUtils.java b/sentry/src/main/java/io/sentry/util/UrlUtils.java index 289a80a17fd..5c0ec5735c1 100644 --- a/sentry/src/main/java/io/sentry/util/UrlUtils.java +++ b/sentry/src/main/java/io/sentry/util/UrlUtils.java @@ -49,9 +49,7 @@ public final class UrlUtils { public static @Nullable String filterQueryParams( final @Nullable String query, final @NotNull DataCollectionResolver resolver) { - return resolver.isDataCollectionConfigured() - ? HttpUtils.filterQueryParams(query, resolver.getUrlQueryParams()) - : query; + return HttpUtils.filterQueryParams(query, resolver.getUrlQueryParams()); } private static boolean isValidAbsoluteUrl(final @NotNull URI uri) { diff --git a/sentry/src/test/java/io/sentry/DataCollectionResolverTest.kt b/sentry/src/test/java/io/sentry/DataCollectionResolverTest.kt index 375cc96cfb4..5f8651ba07f 100644 --- a/sentry/src/test/java/io/sentry/DataCollectionResolverTest.kt +++ b/sentry/src/test/java/io/sentry/DataCollectionResolverTest.kt @@ -20,248 +20,53 @@ class DataCollectionResolverTest { } @Test - fun `data collection configured reflects namespace explicitness`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.isDataCollectionConfigured).isFalse() - - options.dataCollection.urlQueryParams = KeyValueCollectionBehavior.denyList() - - assertThat(options.dataCollectionResolver.isDataCollectionConfigured).isTrue() - } - - @Test - fun `user info falls back to sendDefaultPii when unset`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.isUserInfo).isFalse() - - options.isSendDefaultPii = true + fun `booleans use data collection defaults when unset`() { + val resolver = SentryOptions().dataCollectionResolver - assertThat(options.dataCollectionResolver.isUserInfo).isTrue() + assertThat(resolver.isUserInfo).isTrue() + assertThat(resolver.isDatabaseQueryData).isTrue() + assertThat(resolver.isFilePaths).isTrue() + assertThat(resolver.isGraphqlDocument).isTrue() + assertThat(resolver.isGraphqlVariables).isTrue() } @Test - fun `user info uses configured Data Collection value`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - options.dataCollection.setUserInfo(false) + fun `booleans use configured data collection values`() { + val options = + SentryOptions().apply { + dataCollection.setUserInfo(false) + dataCollection.setDatabaseQueryData(false) + dataCollection.setFilePaths(false) + dataCollection.graphql.setDocument(false) + dataCollection.graphql.setVariables(false) + } assertThat(options.dataCollectionResolver.isUserInfo).isFalse() - - options.isSendDefaultPii = false - options.dataCollection.setUserInfo(true) - - assertThat(options.dataCollectionResolver.isUserInfo).isTrue() - } - - @Test - fun `omitted booleans use data collection defaults once namespace is explicit`() { - val options = SentryOptions().apply { isSendDefaultPii = false } - - options.dataCollection.cookies = KeyValueCollectionBehavior.off() - - assertThat(options.dataCollectionResolver.isUserInfo).isTrue() - assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue() - assertThat(options.dataCollectionResolver.isFilePaths).isTrue() - assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue() - assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue() - } - - @Test - fun `database query data uses sendDefaultPii when Data Collection is absent`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.isDatabaseQueryData).isFalse() - - options.isSendDefaultPii = true - - assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue() - } - - @Test - fun `database query data uses configured Data Collection value`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - options.dataCollection.setDatabaseQueryData(false) - assertThat(options.dataCollectionResolver.isDatabaseQueryData).isFalse() - - options.isSendDefaultPii = false - options.dataCollection.setDatabaseQueryData(true) - - assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue() - } - - @Test - fun `file paths use sendDefaultPii when Data Collection is absent`() { - val options = SentryOptions() - assertThat(options.dataCollectionResolver.isFilePaths).isFalse() - - options.isSendDefaultPii = true - - assertThat(options.dataCollectionResolver.isFilePaths).isTrue() - } - - @Test - fun `file paths use configured Data Collection value`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - options.dataCollection.setFilePaths(false) - - assertThat(options.dataCollectionResolver.isFilePaths).isFalse() - - options.isSendDefaultPii = false - options.dataCollection.setFilePaths(true) - - assertThat(options.dataCollectionResolver.isFilePaths).isTrue() - } - - @Test - fun `GraphQL document uses sendDefaultPii when Data Collection is absent`() { - val options = SentryOptions() - assertThat(options.dataCollectionResolver.isGraphqlDocument).isFalse() - - options.isSendDefaultPii = true - - assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue() - } - - @Test - fun `GraphQL document uses configured Data Collection value`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - options.dataCollection.graphql.setDocument(false) - - assertThat(options.dataCollectionResolver.isGraphqlDocument).isFalse() - - options.isSendDefaultPii = false - options.dataCollection.graphql.setDocument(true) - - assertThat(options.dataCollectionResolver.isGraphqlDocument).isTrue() - } - - @Test - fun `GraphQL variables use sendDefaultPii when Data Collection is absent`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.isGraphqlVariables).isFalse() - - options.isSendDefaultPii = true - - assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue() - } - - @Test - fun `GraphQL variables use configured Data Collection value`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - options.dataCollection.graphql.setVariables(false) - assertThat(options.dataCollectionResolver.isGraphqlVariables).isFalse() - - options.isSendDefaultPii = false - options.dataCollection.graphql.setVariables(true) - - assertThat(options.dataCollectionResolver.isGraphqlVariables).isTrue() } @Test - fun `GraphQL legacy body variants preserve the legacy size gate when namespace is absent`() { - val options = - SentryOptions().apply { - isSendDefaultPii = true - maxRequestBodySize = SentryOptions.RequestSize.NONE - } - - assertThat(options.dataCollectionResolver.isGraphqlDocumentWithLegacyBodyGate).isFalse() - assertThat(options.dataCollectionResolver.isGraphqlVariablesWithLegacyBodyGate).isFalse() - - options.maxRequestBodySize = SentryOptions.RequestSize.SMALL - - assertThat(options.dataCollectionResolver.isGraphqlDocumentWithLegacyBodyGate).isTrue() - assertThat(options.dataCollectionResolver.isGraphqlVariablesWithLegacyBodyGate).isTrue() - } - - @Test - fun `outgoing response legacy body variant preserves the legacy size gate`() { - val options = - SentryOptions().apply { - isSendDefaultPii = true - maxRequestBodySize = SentryOptions.RequestSize.NONE - } - - assertThat(options.dataCollectionResolver.isOutgoingResponseBodyWithLegacyBodyGate).isFalse() - - options.maxRequestBodySize = SentryOptions.RequestSize.SMALL - - assertThat(options.dataCollectionResolver.isOutgoingResponseBodyWithLegacyBodyGate).isTrue() - } - - @Test - fun `outgoing response legacy body variant uses data collection when namespace is explicit`() { - val options = - SentryOptions().apply { - isSendDefaultPii = false - maxRequestBodySize = SentryOptions.RequestSize.NONE - dataCollection.graphql.setDocument(true) - } - - assertThat(options.dataCollectionResolver.isOutgoingResponseBodyWithLegacyBodyGate).isTrue() - - options.dataCollection.httpBodies = emptySet() - - assertThat(options.dataCollectionResolver.isOutgoingResponseBodyWithLegacyBodyGate).isFalse() - } - - @Test - fun `GraphQL legacy body variants ignore the size option when namespace is explicit`() { - val options = - SentryOptions().apply { - isSendDefaultPii = false - maxRequestBodySize = SentryOptions.RequestSize.NONE - dataCollection.graphql.setDocument(true) - dataCollection.graphql.setVariables(true) - } - - assertThat(options.dataCollectionResolver.isGraphqlDocumentWithLegacyBodyGate).isTrue() - assertThat(options.dataCollectionResolver.isGraphqlVariablesWithLegacyBodyGate).isTrue() - } - - @Test - fun `GraphQL document legacy always variant preserves collection when namespace is absent`() { - val options = SentryOptions().apply { isSendDefaultPii = false } - - assertThat(options.dataCollectionResolver.isGraphqlDocumentWithLegacyAlways).isTrue() - - options.dataCollection.graphql.setDocument(false) - - assertThat(options.dataCollectionResolver.isGraphqlDocumentWithLegacyAlways).isFalse() - } - - @Test - fun `GraphQL variables legacy always variant preserves collection when namespace is absent`() { - val options = SentryOptions().apply { isSendDefaultPii = false } - - assertThat(options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways).isTrue() - - options.dataCollection.graphql.setVariables(false) - - assertThat(options.dataCollectionResolver.isGraphqlVariablesWithLegacyAlways).isFalse() + fun `cookies use default deny list when unset`() { + assertThat(SentryOptions().dataCollectionResolver.cookies) + .isEqualTo(KeyValueCollectionBehavior.denyList()) } @Test - fun `cookies are off when unset and sendDefaultPii is false`() { + fun `cookies use configured data collection behavior`() { val options = SentryOptions() + val behavior = KeyValueCollectionBehavior.allowList("language", "theme") - assertThat(options.dataCollectionResolver.cookies).isEqualTo(KeyValueCollectionBehavior.off()) + options.dataCollection.cookies = behavior + + assertThat(options.dataCollectionResolver.cookies).isEqualTo(behavior) } @Test fun `mutating one fallback key-value behavior does not affect other getters`() { - val resolver = SentryOptions().apply { dataCollection.setUserInfo(true) }.dataCollectionResolver + val resolver = SentryOptions().dataCollectionResolver resolver.cookies.terms = listOf("custom-cookie") @@ -270,44 +75,14 @@ class DataCollectionResolverTest { assertThat(resolver.httpResponseHeaders.terms).doesNotContain("custom-cookie") } - @Test - fun `cookies use default deny list when unset and sendDefaultPii is true`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - assertThat(options.dataCollectionResolver.cookies) - .isEqualTo(KeyValueCollectionBehavior.denyList()) - } - - @Test - fun `cookies use default deny list when namespace is explicit`() { - val options = SentryOptions().apply { isSendDefaultPii = false } - - options.dataCollection.setUserInfo(false) - - assertThat(options.dataCollectionResolver.cookies) - .isEqualTo(KeyValueCollectionBehavior.denyList()) - } - - @Test - fun `cookies use configured Data Collection behavior`() { - val options = SentryOptions().apply { isSendDefaultPii = false } - val behavior = KeyValueCollectionBehavior.allowList("language", "theme") - - options.dataCollection.cookies = behavior - - assertThat(options.dataCollectionResolver.cookies).isEqualTo(behavior) - } - @Test fun `URL query params use default deny list when unset`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.urlQueryParams) + assertThat(SentryOptions().dataCollectionResolver.urlQueryParams) .isEqualTo(KeyValueCollectionBehavior.denyList()) } @Test - fun `URL query params use configured Data Collection behavior`() { + fun `URL query params use configured data collection behavior`() { val options = SentryOptions() val behavior = KeyValueCollectionBehavior.allowList("language", "theme") @@ -318,14 +93,12 @@ class DataCollectionResolverTest { @Test fun `HTTP request headers use default deny list when unset`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.httpRequestHeaders) + assertThat(SentryOptions().dataCollectionResolver.httpRequestHeaders) .isEqualTo(KeyValueCollectionBehavior.denyList()) } @Test - fun `HTTP request headers use configured Data Collection behavior`() { + fun `HTTP request headers use configured data collection behavior`() { val options = SentryOptions() val behavior = KeyValueCollectionBehavior.allowList("content-type") @@ -336,14 +109,12 @@ class DataCollectionResolverTest { @Test fun `HTTP response headers use default deny list when unset`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.httpResponseHeaders) + assertThat(SentryOptions().dataCollectionResolver.httpResponseHeaders) .isEqualTo(KeyValueCollectionBehavior.denyList()) } @Test - fun `HTTP response headers use configured Data Collection behavior`() { + fun `HTTP response headers use configured data collection behavior`() { val options = SentryOptions() val behavior = KeyValueCollectionBehavior.off() @@ -353,35 +124,18 @@ class DataCollectionResolverTest { } @Test - fun `HTTP bodies preserve direction-specific legacy fallbacks when data collection is absent`() { - val options = SentryOptions() - - assertThat(options.dataCollectionResolver.isIncomingRequestBody).isFalse() - assertThat(options.dataCollectionResolver.isOutgoingRequestBody).isTrue() - assertThat(options.dataCollectionResolver.isIncomingResponseBody).isTrue() - assertThat(options.dataCollectionResolver.isOutgoingResponseBody).isFalse() - - options.isSendDefaultPii = true - - assertThat(options.dataCollectionResolver.isIncomingRequestBody).isTrue() - assertThat(options.dataCollectionResolver.isOutgoingRequestBody).isTrue() - assertThat(options.dataCollectionResolver.isIncomingResponseBody).isTrue() - assertThat(options.dataCollectionResolver.isOutgoingResponseBody).isTrue() - } - - @Test - fun `explicit empty data collection enables every HTTP body direction`() { - val options = SentryOptions().apply { dataCollection.forceDataCollection() } + fun `HTTP bodies use data collection defaults when unset`() { + val resolver = SentryOptions().dataCollectionResolver - assertThat(options.dataCollectionResolver.isIncomingRequestBody).isTrue() - assertThat(options.dataCollectionResolver.isOutgoingRequestBody).isTrue() - assertThat(options.dataCollectionResolver.isIncomingResponseBody).isTrue() - assertThat(options.dataCollectionResolver.isOutgoingResponseBody).isTrue() + assertThat(resolver.isIncomingRequestBody).isTrue() + assertThat(resolver.isOutgoingRequestBody).isTrue() + assertThat(resolver.isIncomingResponseBody).isTrue() + assertThat(resolver.isOutgoingResponseBody).isTrue() } @Test fun `explicit HTTP body set controls every direction`() { - val options = SentryOptions().apply { isSendDefaultPii = true } + val options = SentryOptions() options.dataCollection.httpBodies = setOf(HttpBodyType.INCOMING_REQUEST, HttpBodyType.OUTGOING_RESPONSE) @@ -391,4 +145,14 @@ class DataCollectionResolverTest { assertThat(options.dataCollectionResolver.isIncomingResponseBody).isFalse() assertThat(options.dataCollectionResolver.isOutgoingResponseBody).isTrue() } + + @Test + fun `empty HTTP body set disables every direction`() { + val options = SentryOptions().apply { dataCollection.httpBodies = emptySet() } + + assertThat(options.dataCollectionResolver.isIncomingRequestBody).isFalse() + assertThat(options.dataCollectionResolver.isOutgoingRequestBody).isFalse() + assertThat(options.dataCollectionResolver.isIncomingResponseBody).isFalse() + assertThat(options.dataCollectionResolver.isOutgoingResponseBody).isFalse() + } } diff --git a/sentry/src/test/java/io/sentry/DataCollectionTest.kt b/sentry/src/test/java/io/sentry/DataCollectionTest.kt index ae4bc3a0562..60a18be648b 100644 --- a/sentry/src/test/java/io/sentry/DataCollectionTest.kt +++ b/sentry/src/test/java/io/sentry/DataCollectionTest.kt @@ -6,7 +6,7 @@ import kotlin.test.assertFailsWith class DataCollectionTest { @Test - fun `public constructor does not force Data Collection for empty configuration`() { + fun `public constructor has no explicit overrides`() { val dataCollection = DataCollection() assertThat(dataCollection.userInfo).isNull() @@ -22,15 +22,6 @@ class DataCollectionTest { assertThat(dataCollection.isExplicitlyConfigured()).isFalse() } - @Test - fun `force Data Collection makes empty configuration explicit`() { - val dataCollection = DataCollection() - - dataCollection.forceDataCollection() - - assertThat(dataCollection.isExplicitlyConfigured()).isTrue() - } - @Test fun `nested override makes configuration explicit`() { val dataCollection = DataCollection() diff --git a/sentry/src/test/java/io/sentry/ExternalOptionsTest.kt b/sentry/src/test/java/io/sentry/ExternalOptionsTest.kt index 8e98e6c60b8..734bde9ccc0 100644 --- a/sentry/src/test/java/io/sentry/ExternalOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/ExternalOptionsTest.kt @@ -102,18 +102,6 @@ class ExternalOptionsTest { } } - @Test - fun `external data collection takes precedence over external send default PII`() { - withPropertiesFile(listOf("send-default-pii=false", "data-collection.cookies.mode=off")) { - externalOptions -> - val options = SentryOptions().apply { merge(externalOptions) } - - assertThat(options.isSendDefaultPii).isFalse() - assertThat(options.dataCollectionResolver.isUserInfo).isTrue() - assertThat(options.dataCollectionResolver.cookies).isEqualTo(KeyValueCollectionBehavior.off()) - } - } - @Test fun `creates options with proxy using external properties`() { withPropertiesFile( @@ -569,13 +557,6 @@ class ExternalOptionsTest { } } - @Test - fun `creates options with sendDefaultPii set to true`() { - withPropertiesFile("send-default-pii=true") { options -> - assertTrue(options.isSendDefaultPii == true) - } - } - @Test fun `creates options with forceInit set to true`() { withPropertiesFile("force-init=true") { options -> assertTrue(options.isForceInit == true) } diff --git a/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt b/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt index 7529d0a3e54..d4469f4f6ea 100644 --- a/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt @@ -51,7 +51,6 @@ class MainEventProcessorTest { attachStackTrace: Boolean = true, environment: String? = "environment", tags: Map = emptyMap(), - sendDefaultPii: Boolean? = null, serverName: String? = "server", host: String? = null, resolveHostDelay: Long? = null, @@ -65,9 +64,6 @@ class MainEventProcessorTest { sentryOptions.environment = environment sentryOptions.serverName = serverName sentryOptions.setModulesLoader { modules } - if (sendDefaultPii != null) { - sentryOptions.isSendDefaultPii = sendDefaultPii - } if (proguardUuid != null) { sentryOptions.proguardUuid = proguardUuid } @@ -302,24 +298,16 @@ class MainEventProcessorTest { @Test fun `when event does not have ip address set, sets {{auto}} as the ip address`() { - val sut = fixture.getSut(sendDefaultPii = true) + val sut = fixture.getSut() val event = SentryEvent() sut.process(event, Hint()) assertNotNull(event.user) { assertEquals("{{auto}}", it.ipAddress) } } @Test - fun `when event does not have ip address set, do not enrich ip address if sendDefaultPii is false`() { - val sut = fixture.getSut(sendDefaultPii = false) - val event = SentryEvent() - sut.process(event, Hint()) - assertNotNull(event.user) { assertNull(it.ipAddress) } - } - - @Test - fun `when user info is disabled, do not enrich ip address if sendDefaultPii is true`() { + fun `when user info is disabled, do not enrich ip address`() { fixture.sentryOptions.dataCollection.setUserInfo(false) - val sut = fixture.getSut(sendDefaultPii = true) + val sut = fixture.getSut() val event = SentryEvent() sut.process(event, Hint()) @@ -328,9 +316,9 @@ class MainEventProcessorTest { } @Test - fun `when user info is enabled, enrich ip address if sendDefaultPii is false`() { + fun `when user info is enabled, enrich ip address`() { fixture.sentryOptions.dataCollection.setUserInfo(true) - val sut = fixture.getSut(sendDefaultPii = false) + val sut = fixture.getSut() val event = SentryEvent() sut.process(event, Hint()) @@ -341,7 +329,7 @@ class MainEventProcessorTest { @Test fun `when another data collection setting is configured, omitted user info uses its default`() { fixture.sentryOptions.dataCollection.cookies = KeyValueCollectionBehavior.off() - val sut = fixture.getSut(sendDefaultPii = false) + val sut = fixture.getSut() val event = SentryEvent() sut.process(event, Hint()) @@ -351,7 +339,7 @@ class MainEventProcessorTest { @Test fun `when event has ip address set, keeps original ip address`() { - val sut = fixture.getSut(sendDefaultPii = true) + val sut = fixture.getSut() val event = SentryEvent() event.user = User().apply { ipAddress = "192.168.0.1" } sut.process(event, Hint()) @@ -494,7 +482,7 @@ class MainEventProcessorTest { @Test fun `User is merged on transaction`() { - val processor = fixture.getSut(sendDefaultPii = true) + val processor = fixture.getSut() var transaction = SentryTransaction(fixture.sentryTracer) transaction = processor.process(transaction, Hint()) diff --git a/sentry/src/test/java/io/sentry/ScopesTest.kt b/sentry/src/test/java/io/sentry/ScopesTest.kt index 4110d8ee843..dff6c7f33bf 100644 --- a/sentry/src/test/java/io/sentry/ScopesTest.kt +++ b/sentry/src/test/java/io/sentry/ScopesTest.kt @@ -3091,46 +3091,7 @@ class ScopesTest { } @Test - fun `adds user fields to log attributes if sendDefaultPii is true`() { - val (sut, mockClient) = - getEnabledScopes { - it.distinctId = "distinctId" - it.isSendDefaultPii = true - } - - sut.configureScope { scope -> - scope.user = - User().also { - it.id = "usrid" - it.username = "usrname" - it.email = "user@sentry.io" - } - } - sut.logger().log(SentryLogLevel.WARN, "log message") - - verify(mockClient) - .captureLog( - check { - assertEquals("log message", it.body) - - val userId = it.attributes?.get("user.id")!! - assertEquals("usrid", userId.value) - assertEquals("string", userId.type) - - val userName = it.attributes?.get("user.name")!! - assertEquals("usrname", userName.value) - assertEquals("string", userName.type) - - val userEmail = it.attributes?.get("user.email")!! - assertEquals("user@sentry.io", userEmail.value) - assertEquals("string", userEmail.type) - }, - anyOrNull(), - ) - } - - @Test - fun `adds user fields to log attributes even if sendDefaultPii is false`() { + fun `adds user fields to log attributes`() { val (sut, mockClient) = getEnabledScopes { it.distinctId = "distinctId" @@ -3212,11 +3173,7 @@ class ScopesTest { @Test fun `missing user fields do not break attributes`() { - val (sut, mockClient) = - getEnabledScopes { - it.isSendDefaultPii = true - it.distinctId = "distinctId" - } + val (sut, mockClient) = getEnabledScopes { it.distinctId = "distinctId" } sut.configureScope { scope -> scope.user = User() } sut.logger().log(SentryLogLevel.WARN, "log message") @@ -4094,47 +4051,7 @@ class ScopesTest { } @Test - fun `adds user fields to metric attributes if sendDefaultPii is true`() { - val (sut, mockClient) = - getEnabledScopes { - it.distinctId = "distinctId" - it.isSendDefaultPii = true - } - - sut.configureScope { scope -> - scope.user = - User().also { - it.id = "usrid" - it.username = "usrname" - it.email = "user@sentry.io" - } - } - sut.metrics().count("metric name") - - verify(mockClient) - .captureMetric( - check { - assertEquals("metric name", it.name) - - val userId = it.attributes?.get("user.id")!! - assertEquals("usrid", userId.value) - assertEquals("string", userId.type) - - val userName = it.attributes?.get("user.name")!! - assertEquals("usrname", userName.value) - assertEquals("string", userName.type) - - val userEmail = it.attributes?.get("user.email")!! - assertEquals("user@sentry.io", userEmail.value) - assertEquals("string", userEmail.type) - }, - anyOrNull(), - anyOrNull(), - ) - } - - @Test - fun `adds user fields to metric attributes even if sendDefaultPii is false`() { + fun `adds user fields to metric attributes`() { val (sut, mockClient) = getEnabledScopes { it.distinctId = "distinctId" } sut.configureScope { scope -> @@ -4210,11 +4127,7 @@ class ScopesTest { @Test fun `missing user fields do not break attributes for metrics`() { - val (sut, mockClient) = - getEnabledScopes { - it.isSendDefaultPii = true - it.distinctId = "distinctId" - } + val (sut, mockClient) = getEnabledScopes { it.distinctId = "distinctId" } sut.configureScope { scope -> scope.user = User() } sut.metrics().count("metric name") diff --git a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt index 309c6f98031..33bbe019543 100644 --- a/sentry/src/test/java/io/sentry/SentryOptionsTest.kt +++ b/sentry/src/test/java/io/sentry/SentryOptionsTest.kt @@ -53,7 +53,7 @@ class SentryOptionsTest { } @Test - fun `setting an empty data collection preserves legacy mode`() { + fun `setting an empty data collection leaves all overrides unset`() { val options = SentryOptions() options.dataCollection = DataCollection() @@ -61,25 +61,6 @@ class SentryOptionsTest { assertThat(options.dataCollection.isExplicitlyConfigured()).isFalse() } - @Test - fun `forcing empty data collection marks it explicitly configured`() { - val options = SentryOptions() - - options.dataCollection.forceDataCollection() - - assertThat(options.dataCollection.isExplicitlyConfigured()).isTrue() - } - - @Test - fun `forcing data collection preserves existing options`() { - val options = SentryOptions() - options.dataCollection.setUserInfo(false) - - options.dataCollection.forceDataCollection() - - assertThat(options.dataCollection.userInfo).isFalse() - } - @Test fun `setting data collection replaces the default instance`() { val options = SentryOptions() @@ -107,7 +88,7 @@ class SentryOptionsTest { } @Test - fun `merging absent external data collection preserves legacy mode`() { + fun `merging absent external data collection leaves all overrides unset`() { val options = SentryOptions() options.merge(ExternalOptions()) @@ -171,24 +152,6 @@ class SentryOptionsTest { assertThat(options.dataCollection.filePaths).isFalse() } - @Test - fun `external data collection takes precedence over send default PII`() { - val externalOptions = - ExternalOptions().apply { - isSendDefaultPii = false - dataCollection = DataCollection().apply { cookies = KeyValueCollectionBehavior.off() } - } - val options = SentryOptions() - - options.merge(externalOptions) - - assertThat(options.isSendDefaultPii).isFalse() - assertThat(options.dataCollection.isExplicitlyConfigured()).isTrue() - assertThat(options.dataCollectionResolver.isUserInfo).isTrue() - assertThat(options.dataCollectionResolver.isDatabaseQueryData).isTrue() - assertThat(options.dataCollectionResolver.cookies).isEqualTo(KeyValueCollectionBehavior.off()) - } - @Test fun `when options is initialized, logger is not null`() { assertNotNull(SentryOptions().logger) @@ -580,7 +543,6 @@ class SentryOptionsTest { externalOptions.isEnableDatabaseTransactionTracing = true externalOptions.isEnableCacheTracing = true externalOptions.maxRequestBodySize = SentryOptions.RequestSize.MEDIUM - externalOptions.isSendDefaultPii = true externalOptions.isForceInit = true externalOptions.cron = SentryOptions.Cron().apply { @@ -658,7 +620,6 @@ class SentryOptionsTest { assertEquals(40L, options.cron?.defaultFailureIssueThreshold) assertEquals(50L, options.cron?.defaultRecoveryThreshold) assertEquals("America/New_York", options.cron?.defaultTimezone) - assertTrue(options.isSendDefaultPii) assertEquals(RequestSize.MEDIUM, options.maxRequestBodySize) assertTrue(options.isEnableSpotlight) assertEquals("http://local.sentry.io:1234", options.spotlightConnectionUrl) diff --git a/sentry/src/test/java/io/sentry/SentryTracerTest.kt b/sentry/src/test/java/io/sentry/SentryTracerTest.kt index 0e225306fe2..c9f394a288d 100644 --- a/sentry/src/test/java/io/sentry/SentryTracerTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTracerTest.kt @@ -1026,12 +1026,7 @@ class SentryTracerTest { @Test fun `returns trace state`() { - val transaction = - fixture.getSut( - { - it.isSendDefaultPii = true - }, - ) + val transaction = fixture.getSut() fixture.scopes.setUser(User().apply { id = "user-id" }) val replayId = SentryId() fixture.scopes.configureScope { it.replayId = replayId } @@ -1067,7 +1062,7 @@ class SentryTracerTest { } @Test - fun `returns trace state without userId if not send pii`() { + fun `returns trace state without userId`() { val transaction = fixture.getSut() fixture.scopes.setUser(User().apply { id = "user-id" }) val trace = transaction.traceContext() @@ -1107,7 +1102,6 @@ class SentryTracerTest { { it.environment = "production" it.release = "1.0.99-rc.7" - it.isSendDefaultPii = true }, ) @@ -1131,7 +1125,7 @@ class SentryTracerTest { } @Test - fun `returns baggage header without userId if not send pii`() { + fun `returns baggage header without userId`() { val transaction = fixture.getSut( { @@ -1157,13 +1151,12 @@ class SentryTracerTest { } @Test - fun `returns baggage header without userId if send pii and null user`() { + fun `returns baggage header without userId if user is null`() { val transaction = fixture.getSut( { it.environment = "production" it.release = "1.0.99-rc.7" - it.isSendDefaultPii = true }, ) diff --git a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileInputStreamTest.kt b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileInputStreamTest.kt index 36c1787d9ec..0ae64ae336e 100644 --- a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileInputStreamTest.kt +++ b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileInputStreamTest.kt @@ -38,13 +38,13 @@ class SentryFileInputStreamTest { tmpFile: File? = null, activeTransaction: Boolean = true, fileDescriptor: FileDescriptor? = null, - sendDefaultPii: Boolean = false, + filePaths: Boolean? = null, ): FileInputStream { tmpFile?.writeText("Text") whenever(scopes.options) .thenReturn( options.apply { - isSendDefaultPii = sendDefaultPii + filePaths?.let { dataCollection.setFilePaths(it) } threadChecker = ThreadChecker.getInstance() addInAppInclude("org.junit") }, @@ -113,8 +113,8 @@ class SentryFileInputStreamTest { } @Test - fun `captures file name in description and file path when isSendDefaultPii is true`() { - val fis = fixture.getSut(tmpFile, sendDefaultPii = true) + fun `captures file name in description and file path by default`() { + val fis = fixture.getSut(tmpFile) fis.close() val fileIOSpan = fixture.sentryTracer.children.first() @@ -123,8 +123,8 @@ class SentryFileInputStreamTest { } @Test - fun `captures only file extension in description when isSendDefaultPii is false`() { - val fis = fixture.getSut(tmpFile, sendDefaultPii = false) + fun `captures only file extension in description when file paths are disabled`() { + val fis = fixture.getSut(tmpFile, filePaths = false) fis.close() val fileIOSpan = fixture.sentryTracer.children.first() @@ -133,8 +133,8 @@ class SentryFileInputStreamTest { } @Test - fun `captures only file size if no extension is available when isSendDefaultPii is false`() { - val fis = fixture.getSut(tmpFileWithoutExtension, sendDefaultPii = false) + fun `captures only file size if no extension is available and file paths are disabled`() { + val fis = fixture.getSut(tmpFileWithoutExtension, filePaths = false) fis.close() val fileIOSpan = fixture.sentryTracer.children.first() @@ -154,7 +154,7 @@ class SentryFileInputStreamTest { fixture.getSut(tmpFile).use { it.read() } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (1 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (1 B)") assertEquals(fileIOSpan.data["file.size"], 1L) } @@ -163,7 +163,7 @@ class SentryFileInputStreamTest { fixture.getSut(tmpFile).use { it.read(ByteArray(10)) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (4 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") assertEquals(fileIOSpan.data["file.size"], 4L) } @@ -172,7 +172,7 @@ class SentryFileInputStreamTest { fixture.getSut(tmpFile).use { it.read(ByteArray(10), 1, 3) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (3 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (3 B)") assertEquals(fileIOSpan.data["file.size"], 3L) } @@ -181,7 +181,7 @@ class SentryFileInputStreamTest { fixture.getSut(tmpFile).use { it.skip(10) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (10 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (10 B)") assertEquals(fileIOSpan.data["file.size"], 10L) } @@ -190,7 +190,7 @@ class SentryFileInputStreamTest { fixture.getSut(tmpFile).use { it.reader().readText() } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (4 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") assertEquals(fileIOSpan.data["file.size"], 4L) } @@ -236,9 +236,9 @@ class SentryFileInputStreamTest { } @Test - fun `when run on JVM and sendDefaultPii is enabled reports file path`() { + fun `when run on JVM reports file path by default`() { val file = tmpFile - fixture.getSut(file, sendDefaultPii = true).use { it.readAllBytes() } + fixture.getSut(file).use { it.readAllBytes() } val fileIOSpan = fixture.sentryTracer.children.first() assertEquals(fileIOSpan.data["file.path"], file.absolutePath) } diff --git a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileOutputStreamTest.kt b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileOutputStreamTest.kt index a7927cebf2d..7f3ae02a2e8 100644 --- a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileOutputStreamTest.kt +++ b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileOutputStreamTest.kt @@ -104,7 +104,8 @@ class SentryFileOutputStreamTest { assertEquals(fixture.sentryTracer.children.size, 1) val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (0 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (0 B)") + assertNotNull(fileIOSpan.data["file.path"]) assertEquals(fileIOSpan.data["file.size"], 0L) assertEquals(fileIOSpan.throwable, null) assertEquals(fileIOSpan.isFinished, true) @@ -112,18 +113,8 @@ class SentryFileOutputStreamTest { } @Test - fun `captures file name in description and file path when isSendDefaultPii is true`() { - val fos = fixture.getSut(tmpFile) { it.isSendDefaultPii = true } - fos.close() - - val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "test.txt (0 B)") - assertNotNull(fileIOSpan.data["file.path"]) - } - - @Test - fun `captures only file extension in description when isSendDefaultPii is false`() { - val fos = fixture.getSut(tmpFile) { it.isSendDefaultPii = false } + fun `captures only file extension in description when file paths are disabled`() { + val fos = fixture.getSut(tmpFile) { it.dataCollection.setFilePaths(false) } fos.close() val fileIOSpan = fixture.sentryTracer.children.first() @@ -132,8 +123,11 @@ class SentryFileOutputStreamTest { } @Test - fun `captures only file size if no extension is available when isSendDefaultPii is false`() { - val fos = fixture.getSut(tmpFileWithoutExtension) { it.isSendDefaultPii = false } + fun `captures only file size if no extension is available and file paths are disabled`() { + val fos = + fixture.getSut(tmpFileWithoutExtension) { + it.dataCollection.setFilePaths(false) + } fos.close() val fileIOSpan = fixture.sentryTracer.children.first() @@ -153,7 +147,7 @@ class SentryFileOutputStreamTest { fixture.getSut(tmpFile).use { it.write(29) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (1 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (1 B)") assertEquals(fileIOSpan.data["file.size"], 1L) } @@ -162,7 +156,7 @@ class SentryFileOutputStreamTest { fixture.getSut(tmpFile).use { it.write(ByteArray(10)) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (10 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (10 B)") assertEquals(fileIOSpan.data["file.size"], 10L) } @@ -171,7 +165,7 @@ class SentryFileOutputStreamTest { fixture.getSut(tmpFile).use { it.write(ByteArray(10), 1, 3) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (3 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (3 B)") assertEquals(fileIOSpan.data["file.size"], 3L) } @@ -180,7 +174,7 @@ class SentryFileOutputStreamTest { fixture.getSut(tmpFile).use { it.write("Text".toByteArray()) } val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "***.txt (4 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") assertEquals(fileIOSpan.data["file.size"], 4L) } diff --git a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileReaderTest.kt b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileReaderTest.kt index 85e28b478c9..3be49ce4ab5 100644 --- a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileReaderTest.kt +++ b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileReaderTest.kt @@ -61,7 +61,8 @@ class SentryFileReaderTest { assertEquals(fixture.sentryTracer.children.size, 1) val fileIOSpan = fixture.sentryTracer.children.first() assertEquals(fileIOSpan.spanContext.operation, "file.read") - assertEquals(fileIOSpan.spanContext.description, "***.txt (4 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") + assertNotNull(fileIOSpan.data["file.path"]) assertEquals(fileIOSpan.data["file.size"], 4L) assertEquals(fileIOSpan.throwable, null) assertEquals(fileIOSpan.isFinished, true) @@ -70,23 +71,8 @@ class SentryFileReaderTest { } @Test - fun `captures file name in description and file path when isSendDefaultPii is true`() { - val reader = fixture.getSut(tmpFile) { it.isSendDefaultPii = true } - reader.readText() - reader.close() - - val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") - assertNotNull(fileIOSpan.data["file.path"]) - } - - @Test - fun `configured file paths false overrides sendDefaultPii true`() { - val reader = - fixture.getSut(tmpFile) { - it.isSendDefaultPii = true - it.dataCollection.setFilePaths(false) - } + fun `configured file paths false omits file path`() { + val reader = fixture.getSut(tmpFile) { it.dataCollection.setFilePaths(false) } reader.readText() reader.close() @@ -96,23 +82,8 @@ class SentryFileReaderTest { } @Test - fun `configured file paths true overrides sendDefaultPii false`() { - val reader = - fixture.getSut(tmpFile) { - it.isSendDefaultPii = false - it.dataCollection.setFilePaths(true) - } - reader.readText() - reader.close() - - val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") - assertNotNull(fileIOSpan.data["file.path"]) - } - - @Test - fun `captures only file extension in description when isSendDefaultPii is false`() { - val reader = fixture.getSut(tmpFile) { it.isSendDefaultPii = false } + fun `captures only file extension in description when file paths are disabled`() { + val reader = fixture.getSut(tmpFile) { it.dataCollection.setFilePaths(false) } reader.readText() reader.close() @@ -122,8 +93,11 @@ class SentryFileReaderTest { } @Test - fun `captures only file size if no extension is available when isSendDefaultPii is false`() { - val reader = fixture.getSut(tmpFileWithoutExtension) { it.isSendDefaultPii = false } + fun `captures only file size if no extension is available and file paths are disabled`() { + val reader = + fixture.getSut(tmpFileWithoutExtension) { + it.dataCollection.setFilePaths(false) + } reader.readText() reader.close() diff --git a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileWriterTest.kt b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileWriterTest.kt index 5986175a09c..935f8a49313 100644 --- a/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileWriterTest.kt +++ b/sentry/src/test/java/io/sentry/instrumentation/file/SentryFileWriterTest.kt @@ -59,7 +59,8 @@ class SentryFileWriterTest { assertEquals(fixture.sentryTracer.children.size, 1) val fileIOSpan = fixture.sentryTracer.children.first() assertEquals(fileIOSpan.spanContext.operation, "file.write") - assertEquals(fileIOSpan.spanContext.description, "***.txt (4 B)") + assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") + assertNotNull(fileIOSpan.data["file.path"]) assertEquals(fileIOSpan.data["file.size"], 4L) assertEquals(fileIOSpan.throwable, null) assertEquals(fileIOSpan.isFinished, true) @@ -80,19 +81,8 @@ class SentryFileWriterTest { } @Test - fun `captures file name in description and file path when isSendDefaultPii is true`() { - val writer = fixture.getSut(tmpFile) { it.isSendDefaultPii = true } - writer.write("TEXT") - writer.close() - - val fileIOSpan = fixture.sentryTracer.children.first() - assertEquals(fileIOSpan.spanContext.description, "test.txt (4 B)") - assertNotNull(fileIOSpan.data["file.path"]) - } - - @Test - fun `captures only file extension in description when isSendDefaultPii is false`() { - val writer = fixture.getSut(tmpFile) { it.isSendDefaultPii = false } + fun `captures only file extension in description when file paths are disabled`() { + val writer = fixture.getSut(tmpFile) { it.dataCollection.setFilePaths(false) } writer.write("TEXT") writer.close() @@ -102,8 +92,11 @@ class SentryFileWriterTest { } @Test - fun `captures only file size if no extension is available when isSendDefaultPii is false`() { - val writer = fixture.getSut(tmpFileWithoutExtension) { it.isSendDefaultPii = false } + fun `captures only file size if no extension is available and file paths are disabled`() { + val writer = + fixture.getSut(tmpFileWithoutExtension) { + it.dataCollection.setFilePaths(false) + } writer.write("TEXT") writer.close() diff --git a/sentry/src/test/java/io/sentry/util/CookieUtilsTest.kt b/sentry/src/test/java/io/sentry/util/CookieUtilsTest.kt index 9873cbb6d63..183dec4a128 100644 --- a/sentry/src/test/java/io/sentry/util/CookieUtilsTest.kt +++ b/sentry/src/test/java/io/sentry/util/CookieUtilsTest.kt @@ -12,20 +12,13 @@ import kotlin.test.assertNull class CookieUtilsTest { @Test - fun `options cookie filters omit cookies in legacy mode without default pii`() { + fun `options cookie filters use default deny list`() { val options = SentryOptions() - assertThat(CookieUtils.filterCookies("sessionId=secret", options)).isNull() - assertThat(CookieUtils.filterSetCookie("sessionId=secret; Path=/", options)).isNull() - } - - @Test - fun `options cookie filters preserve cookies in legacy mode with default pii`() { - val options = SentryOptions().apply { isSendDefaultPii = true } - - assertThat(CookieUtils.filterCookies("sessionId=secret", options)).isEqualTo("sessionId=secret") + assertThat(CookieUtils.filterCookies("theme=dark; sessionId=secret", options)) + .isEqualTo("theme=dark; sessionId=[Filtered]") assertThat(CookieUtils.filterSetCookie("sessionId=secret; Path=/", options)) - .isEqualTo("sessionId=secret; Path=/") + .isEqualTo("sessionId=[Filtered]; Path=/") } @Test @@ -44,10 +37,7 @@ class CookieUtilsTest { @Test fun `options cookie filters honor explicitly disabled collection`() { val options = - SentryOptions().apply { - isSendDefaultPii = true - dataCollection.cookies = KeyValueCollectionBehavior.off() - } + SentryOptions().apply { dataCollection.cookies = KeyValueCollectionBehavior.off() } assertThat(CookieUtils.filterCookies("theme=dark", options)).isNull() assertThat(CookieUtils.filterSetCookie("theme=dark; Path=/", options)).isNull() diff --git a/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt b/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt index de8829f7efc..d75dc3f7cc6 100644 --- a/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt +++ b/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt @@ -15,14 +15,14 @@ import org.mockito.kotlin.verify class UrlUtilsTest { @Test - fun `resolver aware helpers preserve legacy query values`() { + fun `resolver aware helpers filter query values by default`() { val resolver = SentryOptions().dataCollectionResolver val details = UrlUtils.parse("https://example.com?token=secret", resolver) val request = Request() details.applyToRequest(request) - assertThat(request.queryString).isEqualTo("token=secret") + assertThat(request.queryString).isEqualTo("token=[Filtered]") } @Test From 968cc2b6172aa6f0465a6e0c36456b3eb49c1f36 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 26 Nov 2026 12:10:43 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29742d9ac0f..8cbddb7be71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - Only the name and no-arg constructor of `SentryAndroidOptions` are kept, instead of every member of every `SentryOptions` subclass. - `sentry-android-ndk` no longer keeps native methods of all `io.sentry.**` classes. `sentry-native-ndk` still keeps its own. - If your code reaches any of these by name through JNI, reflection, or bindings, add your own keep rules for exactly what it uses. -- Remove the deprecated `sendDefaultPii` option from Java APIs, properties and environment variables, Android manifest metadata, and Spring annotations ([#6160](https://github.com/getsentry/sentry-java/issues/6160)) +- Remove the deprecated `sendDefaultPii` option from Java APIs, properties and environment variables, Android manifest metadata, and Spring annotations ([#6793](https://github.com/getsentry/sentry-java/pull/6793)) - Configure automatically collected data with `dataCollection` instead. `DataCollection.forceDataCollection()` is also removed because the defaults now apply automatically. - When no `dataCollection` setting is specified, user information, database query data, file paths, GraphQL documents and variables, and HTTP request and response bodies are enabled. Cookies, URL query parameters, and HTTP headers use their default deny lists. - Logback raw message templates and parameters are controlled only by `includeUnencodedMessage` when an encoder is configured. From 5d944a6efbf514a4b37b475aab017fb0e057c7e1 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 26 Nov 2026 15:12:05 +0100 Subject: [PATCH 3/4] docs: Link Data Collection migration guides --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cbddb7be71..b6a6b695275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ - `sentry-android-ndk` no longer keeps native methods of all `io.sentry.**` classes. `sentry-native-ndk` still keeps its own. - If your code reaches any of these by name through JNI, reflection, or bindings, add your own keep rules for exactly what it uses. - Remove the deprecated `sendDefaultPii` option from Java APIs, properties and environment variables, Android manifest metadata, and Spring annotations ([#6793](https://github.com/getsentry/sentry-java/pull/6793)) - - Configure automatically collected data with `dataCollection` instead. `DataCollection.forceDataCollection()` is also removed because the defaults now apply automatically. + - Configure automatically collected data with `dataCollection` instead. See the Data Collection documentation for [Android](https://docs.sentry.io/platforms/android/configuration/options/#dataCollection), [Java](https://docs.sentry.io/platforms/java/configuration/options/#dataCollection), and [Spring Boot](https://docs.sentry.io/platforms/java/guides/spring-boot/configuration/options/#dataCollection). `DataCollection.forceDataCollection()` is also removed because the defaults now apply automatically. - When no `dataCollection` setting is specified, user information, database query data, file paths, GraphQL documents and variables, and HTTP request and response bodies are enabled. Cookies, URL query parameters, and HTTP headers use their default deny lists. - Logback raw message templates and parameters are controlled only by `includeUnencodedMessage` when an encoder is configured. - The Spring Boot 3 integrations are tested against Spring Boot 3.4 and newer. Spring Boot 3.2 and 3.3 are no longer supported ([#6656](https://github.com/getsentry/sentry-java/pull/6656)) From c6428029b1f21b371581c55e6a047615d4d5bd1c Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 27 Nov 2026 10:27:41 +0100 Subject: [PATCH 4/4] test(transport): Allow platform TLS distrust failures New JDK trust stores reject the compromised eMudhra certificate during the TLS handshake before the SDK-specific check runs. Assert the shared IOException contract so the transport test remains valid across JDK trust store versions. --- .../java/io/sentry/transport/DistrustedCertificatesTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt b/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt index b50cd113c38..7e82725ebbb 100644 --- a/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt +++ b/sentry/src/test/java/io/sentry/transport/DistrustedCertificatesTest.kt @@ -97,7 +97,7 @@ class DistrustedCertificatesTest { false, ) - assertFailsWith { send(trusting(emSignRoot)) } + assertFailsWith { send(trusting(emSignRoot)) } assertThat(server.requestCount).isEqualTo(0) } @@ -107,7 +107,7 @@ class DistrustedCertificatesTest { // Like Android, which completes the chain from intermediates it cached on earlier connections. server.useHttps(serverCertificates(leafIssuedBy(distrustedCa)), false) - assertFailsWith { send(trusting(distrustedCa.certificate)) } + assertFailsWith { send(trusting(distrustedCa.certificate)) } assertThat(server.requestCount).isEqualTo(0) }