From 655d692c3c0f3c311461b2edc2bd46d3ec1347c9 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 30 Nov 2026 12:26:58 +0100 Subject: [PATCH 1/4] fix(core): Filter sensitive URL fragment values Apply the URL query parameter Data Collection policy to fragments so tokens and other sensitive values are not attached in plaintext. Preserve hash routes, anchors, and encoded parameter text while keeping existing query filtering behavior unchanged. --- .../main/java/io/sentry/util/HttpUtils.java | 39 +++++++++--- .../main/java/io/sentry/util/UrlUtils.java | 6 +- .../test/java/io/sentry/util/UrlUtilsTest.kt | 59 ++++++++++++++++++- 3 files changed, 93 insertions(+), 11 deletions(-) diff --git a/sentry/src/main/java/io/sentry/util/HttpUtils.java b/sentry/src/main/java/io/sentry/util/HttpUtils.java index d3a0198064..cfe217317e 100644 --- a/sentry/src/main/java/io/sentry/util/HttpUtils.java +++ b/sentry/src/main/java/io/sentry/util/HttpUtils.java @@ -50,16 +50,41 @@ public final class HttpUtils { if (query == null || behavior.getMode() == KeyValueCollectionBehavior.Mode.OFF) { return null; } + return filterKeyValuePairs(query, behavior, false); + } - final @NotNull StringBuilder filteredQuery = new StringBuilder(); - final @NotNull String[] params = query.split("&", -1); + static @Nullable String filterFragment( + final @Nullable String fragment, final @NotNull KeyValueCollectionBehavior behavior) { + if (fragment == null || behavior.getMode() == KeyValueCollectionBehavior.Mode.OFF) { + return null; + } + + final int querySeparator = fragment.indexOf('?'); + if (querySeparator < 0) { + return filterKeyValuePairs(fragment, behavior, true); + } + return fragment.substring(0, querySeparator + 1) + + filterKeyValuePairs(fragment.substring(querySeparator + 1), behavior, true); + } + + private static @NotNull String filterKeyValuePairs( + final @NotNull String value, + final @NotNull KeyValueCollectionBehavior behavior, + final boolean preserveSegmentsWithoutSeparator) { + final @NotNull StringBuilder filteredValue = new StringBuilder(); + final @NotNull String[] params = value.split("&", -1); for (int i = 0; i < params.length; i++) { if (i > 0) { - filteredQuery.append('&'); + filteredValue.append('&'); } final @NotNull String param = params[i]; final int separator = param.indexOf('='); + if (separator < 0 && preserveSegmentsWithoutSeparator) { + filteredValue.append(param); + continue; + } + final @NotNull String name = separator < 0 ? param : param.substring(0, separator); final @NotNull String decodedName = decodeQueryParamName(name); final boolean sensitive = containsSensitiveDataKey(decodedName); @@ -69,14 +94,14 @@ public final class HttpUtils { || (behavior.getMode() == KeyValueCollectionBehavior.Mode.DENY_LIST && matchesTerm) || (behavior.getMode() == KeyValueCollectionBehavior.Mode.ALLOW_LIST && !matchesTerm); - filteredQuery.append(name); + filteredValue.append(name); if (shouldFilter) { - filteredQuery.append('=').append(SENSITIVE_DATA_SUBSTITUTE); + filteredValue.append('=').append(SENSITIVE_DATA_SUBSTITUTE); } else if (separator >= 0) { - filteredQuery.append(param.substring(separator)); + filteredValue.append(param.substring(separator)); } } - return filteredQuery.toString(); + return filteredValue.toString(); } public static @NotNull Map filterHeaders( diff --git a/sentry/src/main/java/io/sentry/util/UrlUtils.java b/sentry/src/main/java/io/sentry/util/UrlUtils.java index 5c0ec5735c..e6146eed41 100644 --- a/sentry/src/main/java/io/sentry/util/UrlUtils.java +++ b/sentry/src/main/java/io/sentry/util/UrlUtils.java @@ -37,7 +37,11 @@ public final class UrlUtils { final @Nullable String rawQuery = uri.getRawQuery(); final @Nullable String query = resolver == null ? rawQuery : filterQueryParams(rawQuery, resolver); - final @Nullable String fragment = uri.getRawFragment(); + final @Nullable String rawFragment = uri.getRawFragment(); + final @Nullable String fragment = + resolver == null + ? rawFragment + : HttpUtils.filterFragment(rawFragment, resolver.getUrlQueryParams()); final @NotNull String filteredUrl = schemeAndSeparator + filterUserInfo(authority) + path; diff --git a/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt b/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt index d75dc3f7cc..65acdb9e97 100644 --- a/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt +++ b/sentry/src/test/java/io/sentry/util/UrlUtilsTest.kt @@ -52,14 +52,65 @@ class UrlUtilsTest { } @Test - fun `resolver aware helpers remove query values in off mode`() { + fun `resolver aware helpers filter fragment values by default`() { + val details = + UrlUtils.parse( + "https://example.com/callback#access_token=abc123&state=xyz", + SentryOptions().dataCollectionResolver, + ) + val request = Request() + val span = mock() + + details.applyToRequest(request) + details.applyToSpan(span) + + assertThat(request.fragment).isEqualTo("access_token=[Filtered]&state=xyz") + verify(span).setData(SpanDataConvention.HTTP_FRAGMENT_KEY, "access_token=[Filtered]&state=xyz") + } + + @Test + fun `resolver aware helpers filter fragment query after hash route`() { + val details = + UrlUtils.parse( + "https://example.com/#/callback?access_token=abc123&state=xyz", + SentryOptions().dataCollectionResolver, + ) + + assertThat(details.fragment).isEqualTo("/callback?access_token=[Filtered]&state=xyz") + } + + @Test + fun `resolver aware helpers preserve fragment text that is not a key value pair`() { + val details = + UrlUtils.parse("https://example.com/#details", SentryOptions().dataCollectionResolver) + + assertThat(details.fragment).isEqualTo("details") + } + + @Test + fun `resolver aware helpers preserve fragment encoding`() { + val details = + UrlUtils.parse( + "https://example.com/#%61ccess_token=abc%20123&state=a%20b", + SentryOptions().dataCollectionResolver, + ) + + assertThat(details.fragment).isEqualTo("%61ccess_token=[Filtered]&state=a%20b") + } + + @Test + fun `resolver aware helpers remove query and fragment values in off mode`() { val options = SentryOptions().also { it.dataCollection.urlQueryParams = KeyValueCollectionBehavior.off() } - val details = UrlUtils.parse("https://example.com?name=value", options.dataCollectionResolver) + val details = + UrlUtils.parse( + "https://example.com?name=value#access_token=abc123", + options.dataCollectionResolver, + ) val request = Request() val breadcrumb = Breadcrumb.http( - "https://example.com?name=value", + "https://example.com?name=value#access_token=abc123", "GET", null, options.dataCollectionResolver, @@ -68,7 +119,9 @@ class UrlUtilsTest { details.applyToRequest(request) assertThat(request.queryString).isNull() + assertThat(request.fragment).isNull() assertThat(breadcrumb.getData("http.query")).isNull() + assertThat(breadcrumb.getData("http.fragment")).isNull() } @Test From a745e180c272f79500b28f6b2485bf1f44b69094 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 30 Nov 2026 14:20:50 +0100 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b236df97..b320b4ff52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -140,6 +140,7 @@ ### Fixes +- Filter sensitive URL fragment parameters according to the Data Collection policy ([#6814](https://github.com/getsentry/sentry-java/pull/6814)) - Omit request cookies when no cookie headers are present ([#6799](https://github.com/getsentry/sentry-java/pull/6799)) - Set Apollo 3, 4, and 5 HTTP spans to `CANCELLED` instead of `INTERNAL_ERROR` when the request is cancelled ([#6284](https://github.com/getsentry/sentry-java/pull/6284)) - Preserve independent Netty read and write timeout events when exception singletons are reused. These exceptions now bypass event deduplication by default, so applications with multiple capture integrations may report the same timeout more than once. Use `SentryOptions.setIgnoredErrorsForDeduplication(...)` or `ignored-errors-for-deduplication` to customize or clear the default exclusions. ([#6465](https://github.com/getsentry/sentry-java/pull/6465)) From e5eb2e46f4c3392345e73ac6789af64b6e2077dd Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 30 Nov 2026 16:44:06 +0100 Subject: [PATCH 3/4] docs: Mark URL fragment filtering as breaking Move the PR #6814 changelog entry to Breaking Changes and describe how Data Collection now filters or removes URL fragments. Co-Authored-By: Claude --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f28502afb0..ec4f011575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - 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. - OpenTelemetry-derived HTTP headers are controlled by OpenTelemetry capture configuration, not Data Collection, because the SDK can't distinguish manually supplied attributes from values added by automatic instrumentation. Known security cookies remain filtered; use `beforeSendTransaction` for additional scrubbing. +- Apply the Data Collection URL query-parameter policy to URL fragments. Sensitive fragment parameters are now filtered by default, and fragments are omitted when URL query-parameter collection is disabled ([#6814](https://github.com/getsentry/sentry-java/pull/6814)) - 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)) @@ -141,7 +142,6 @@ ### Fixes -- Filter sensitive URL fragment parameters according to the Data Collection policy ([#6814](https://github.com/getsentry/sentry-java/pull/6814)) - Omit request cookies when no cookie headers are present ([#6799](https://github.com/getsentry/sentry-java/pull/6799)) - Set Apollo 3, 4, and 5 HTTP spans to `CANCELLED` instead of `INTERNAL_ERROR` when the request is cancelled ([#6284](https://github.com/getsentry/sentry-java/pull/6284)) - Preserve independent Netty read and write timeout events when exception singletons are reused. These exceptions now bypass event deduplication by default, so applications with multiple capture integrations may report the same timeout more than once. Use `SentryOptions.setIgnoredErrorsForDeduplication(...)` or `ignored-errors-for-deduplication` to customize or clear the default exclusions. ([#6465](https://github.com/getsentry/sentry-java/pull/6465)) From 05db32436f25ef75dfcdcebf56ed0cf3b3b91d36 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 30 Nov 2026 17:36:13 +0100 Subject: [PATCH 4/4] perf(core): Reuse URL filtering behavior Resolve the URL query parameter collection behavior once per parsed URL and reuse it for query and fragment filtering. This avoids allocating the default deny list twice. Co-Authored-By: Claude --- .../src/main/java/io/sentry/util/UrlUtils.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sentry/src/main/java/io/sentry/util/UrlUtils.java b/sentry/src/main/java/io/sentry/util/UrlUtils.java index e6146eed41..b5fd5ce32a 100644 --- a/sentry/src/main/java/io/sentry/util/UrlUtils.java +++ b/sentry/src/main/java/io/sentry/util/UrlUtils.java @@ -2,6 +2,7 @@ import io.sentry.DataCollectionResolver; import io.sentry.ISpan; +import io.sentry.KeyValueCollectionBehavior; import io.sentry.SpanDataConvention; import io.sentry.protocol.Request; import java.net.URI; @@ -35,13 +36,17 @@ public final class UrlUtils { final @NotNull String authority = uri.getRawAuthority() == null ? "" : uri.getRawAuthority(); final @NotNull String path = uri.getRawPath() == null ? "" : uri.getRawPath(); final @Nullable String rawQuery = uri.getRawQuery(); - final @Nullable String query = - resolver == null ? rawQuery : filterQueryParams(rawQuery, resolver); final @Nullable String rawFragment = uri.getRawFragment(); - final @Nullable String fragment = - resolver == null - ? rawFragment - : HttpUtils.filterFragment(rawFragment, resolver.getUrlQueryParams()); + final @Nullable String query; + final @Nullable String fragment; + if (resolver == null) { + query = rawQuery; + fragment = rawFragment; + } else { + final @NotNull KeyValueCollectionBehavior behavior = resolver.getUrlQueryParams(); + query = HttpUtils.filterQueryParams(rawQuery, behavior); + fragment = HttpUtils.filterFragment(rawFragment, behavior); + } final @NotNull String filteredUrl = schemeAndSeparator + filterUserInfo(authority) + path;