@@ -2,6 +2,7 @@ package io.sentry.util
22
33import com.google.common.truth.Truth.assertThat
44import io.sentry.KeyValueCollectionBehavior
5+ import java.util.Locale
56import kotlin.test.Test
67
78class HttpUtilsTest {
@@ -21,6 +22,17 @@ class HttpUtilsTest {
2122 .isEqualTo(" name=value&access_token=[Filtered]&customerId=[Filtered]" )
2223 }
2324
25+ @Test
26+ fun `query parameter deny list matches sensitive names and configured terms regardless of case` () {
27+ assertThat(
28+ HttpUtils .filterQueryParams(
29+ " name=value&ACCESS_TOKEN=secret&customerId=123" ,
30+ KeyValueCollectionBehavior .denyList(" CuStOmEr" ),
31+ ),
32+ )
33+ .isEqualTo(" name=value&ACCESS_TOKEN=[Filtered]&customerId=[Filtered]" )
34+ }
35+
2436 @Test
2537 fun `query parameter allow list only retains allowed non-sensitive values` () {
2638 assertThat(
@@ -32,6 +44,17 @@ class HttpUtilsTest {
3244 .isEqualTo(" name=value&access_token=[Filtered]&customerId=[Filtered]" )
3345 }
3446
47+ @Test
48+ fun `query parameter allow list matches mixed-case terms but still filters sensitive names` () {
49+ assertThat(
50+ HttpUtils .filterQueryParams(
51+ " name=value&AcCeSs_ToKeN=secret&customerId=123" ,
52+ KeyValueCollectionBehavior .allowList(" NaMe" , " AcCeSs_ToKeN" ),
53+ ),
54+ )
55+ .isEqualTo(" name=value&AcCeSs_ToKeN=[Filtered]&customerId=[Filtered]" )
56+ }
57+
3558 @Test
3659 fun `query parameter filter matches decoded names and preserves encoding` () {
3760 assertThat(
@@ -91,6 +114,32 @@ class HttpUtilsTest {
91114 )
92115 }
93116
117+ @Test
118+ fun `header deny list matches sensitive names and configured terms regardless of case` () {
119+ val filtered =
120+ HttpUtils .filterHeaders(
121+ mapOf (
122+ " content-type" to " application/json" ,
123+ " AUTHORIZATION" to " Bearer token" ,
124+ " x-customer" to " customer value" ,
125+ " Cookie" to " name=value" ,
126+ ),
127+ KeyValueCollectionBehavior .denyList(" CuStOmEr" ),
128+ )
129+
130+ assertThat(filtered)
131+ .containsExactly(
132+ " content-type" ,
133+ " application/json" ,
134+ " AUTHORIZATION" ,
135+ " [Filtered]" ,
136+ " x-customer" ,
137+ " [Filtered]" ,
138+ " Cookie" ,
139+ " [Filtered]" ,
140+ )
141+ }
142+
94143 @Test
95144 fun `header allow list only retains allowed non-sensitive values` () {
96145 val filtered =
@@ -113,4 +162,75 @@ class HttpUtilsTest {
113162 " [Filtered]" ,
114163 )
115164 }
165+
166+ @Test
167+ fun `header allow list matches mixed-case terms but still filters sensitive names` () {
168+ val filtered =
169+ HttpUtils .filterHeaders(
170+ mapOf (
171+ " content-type" to " application/json" ,
172+ " AUTHORIZATION" to " Bearer token" ,
173+ " x-customer" to " customer value" ,
174+ ),
175+ KeyValueCollectionBehavior .allowList(" CoNtEnT" , " AuThOrIzAtIoN" ),
176+ )
177+
178+ assertThat(filtered)
179+ .containsExactly(
180+ " content-type" ,
181+ " application/json" ,
182+ " AUTHORIZATION" ,
183+ " [Filtered]" ,
184+ " x-customer" ,
185+ " [Filtered]" ,
186+ )
187+ }
188+
189+ @Test
190+ fun `sensitive data key check rejects an empty key` () {
191+ assertThat(HttpUtils .containsSensitiveDataKey(" " )).isFalse()
192+ }
193+
194+ @Test
195+ fun `sensitive data key check matches independently of the default locale` () {
196+ val originalLocale = Locale .getDefault()
197+ try {
198+ Locale .setDefault(Locale (" tr" , " TR" ))
199+
200+ assertThat(HttpUtils .containsSensitiveDataKey(" SESSION" )).isTrue()
201+ assertThat(HttpUtils .containsSensitiveDataKey(" IDENTITY" )).isTrue()
202+ } finally {
203+ Locale .setDefault(originalLocale)
204+ }
205+ }
206+
207+ @Test
208+ fun `configured term check matches substrings regardless of key and term case` () {
209+ assertThat(HttpUtils .containsTerm(" X-CUSTOMER-ID" , listOf (" CuStOmEr" ))).isTrue()
210+ assertThat(HttpUtils .containsTerm(" X-CUSTOMER-ID" , listOf (" account" ))).isFalse()
211+ }
212+
213+ @Test
214+ fun `configured term check ignores null and empty terms` () {
215+ assertThat(HttpUtils .containsTerm(" customerId" , listOf (null , " " , " CuStOmEr" ))).isTrue()
216+ assertThat(HttpUtils .containsTerm(" customerId" , listOf (null , " " ))).isFalse()
217+ }
218+
219+ @Test
220+ fun `configured term check matches no keys when no terms are configured` () {
221+ assertThat(HttpUtils .containsTerm(" customerId" , emptyList())).isFalse()
222+ }
223+
224+ @Test
225+ fun `configured term check matches independently of the default locale` () {
226+ val originalLocale = Locale .getDefault()
227+ try {
228+ Locale .setDefault(Locale (" tr" , " TR" ))
229+
230+ assertThat(HttpUtils .containsTerm(" DISPLAY" , listOf (" display" ))).isTrue()
231+ assertThat(HttpUtils .containsTerm(" display" , listOf (" DISPLAY" ))).isTrue()
232+ } finally {
233+ Locale .setDefault(originalLocale)
234+ }
235+ }
116236}
0 commit comments