Skip to content

Commit a69b1d7

Browse files
adinauerclaude
andcommitted
fix(core): Avoid sharing Data Collection fallbacks
Create key-value fallback behaviors for each resolver lookup so mutations cannot leak across cookie, query parameter, and header policies. Refs #5666 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 46ecdf0 commit a69b1d7

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

sentry/src/main/java/io/sentry/DataCollectionResolver.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
@ApiStatus.Internal
1010
public final class DataCollectionResolver {
1111

12-
private static final @NotNull KeyValueCollectionBehavior OFF = KeyValueCollectionBehavior.off();
13-
private static final @NotNull KeyValueCollectionBehavior EMPTY_DENY_LIST =
14-
KeyValueCollectionBehavior.denyList();
15-
1612
private final @NotNull SentryOptions options;
1713

1814
DataCollectionResolver(final @NotNull SentryOptions options) {
@@ -71,9 +67,11 @@ public boolean isGraphqlVariablesWithLegacyAlways() {
7167
return cookies;
7268
}
7369
if (isDataCollectionConfigured()) {
74-
return EMPTY_DENY_LIST;
70+
return KeyValueCollectionBehavior.denyList();
7571
}
76-
return options.isSendDefaultPii() ? EMPTY_DENY_LIST : OFF;
72+
return options.isSendDefaultPii()
73+
? KeyValueCollectionBehavior.denyList()
74+
: KeyValueCollectionBehavior.off();
7775
}
7876

7977
public @NotNull KeyValueCollectionBehavior getUrlQueryParams() {
@@ -128,7 +126,7 @@ private boolean explicitOrDefault(
128126

129127
private @NotNull KeyValueCollectionBehavior explicitOrEmptyDenyList(
130128
final @Nullable KeyValueCollectionBehavior explicit) {
131-
return explicit != null ? explicit : EMPTY_DENY_LIST;
129+
return explicit != null ? explicit : KeyValueCollectionBehavior.denyList();
132130
}
133131

134132
private boolean isHttpBodyEnabled(

sentry/src/test/java/io/sentry/DataCollectionResolverTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ class DataCollectionResolverTest {
244244
assertThat(options.dataCollectionResolver.cookies).isEqualTo(KeyValueCollectionBehavior.off())
245245
}
246246

247+
@Test
248+
fun `mutating one fallback key-value behavior does not affect other getters`() {
249+
val resolver = SentryOptions().apply { dataCollection.setUserInfo(true) }.dataCollectionResolver
250+
251+
resolver.cookies.terms = listOf("custom-cookie")
252+
253+
assertThat(resolver.urlQueryParams.terms).doesNotContain("custom-cookie")
254+
assertThat(resolver.httpRequestHeaders.terms).doesNotContain("custom-cookie")
255+
assertThat(resolver.httpResponseHeaders.terms).doesNotContain("custom-cookie")
256+
}
257+
247258
@Test
248259
fun `cookies use default deny list when unset and sendDefaultPii is true`() {
249260
val options = SentryOptions().apply { isSendDefaultPii = true }

0 commit comments

Comments
 (0)