File tree Expand file tree Collapse file tree 7 files changed +40
-6
lines changed
main/java/io/sentry/spring7
test/kotlin/io/sentry/spring7
sentry-spring-jakarta/src
main/java/io/sentry/spring/jakarta
test/kotlin/io/sentry/spring/jakarta
main/java/io/sentry/spring
test/kotlin/io/sentry/spring Expand file tree Collapse file tree 7 files changed +40
-6
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ SentryAndroid.init(
5959### Fixes
6060
6161- Fix missing thread stacks for ANRv1 events ([#4918](https://github.com/getsentry/sentry-java/pull/4918))
62+ - Fix handling of unparseable mime-type on request filter ([#4939](https://github.com/getsentry/sentry-java/pull/4939))
6263
6364### Internal
6465
Original file line number Diff line number Diff line change 2626import org .jetbrains .annotations .NotNull ;
2727import org .jetbrains .annotations .Nullable ;
2828import org .springframework .http .MediaType ;
29+ import org .springframework .util .InvalidMimeTypeException ;
2930import org .springframework .util .MimeType ;
3031import org .springframework .web .filter .OncePerRequestFilter ;
3132import org .springframework .web .util .ContentCachingRequestWrapper ;
@@ -131,8 +132,12 @@ && shouldCacheMimeType(contentType)
131132 }
132133
133134 private static boolean shouldCacheMimeType (String contentType ) {
134- return MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_JSON )
135- || MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_FORM_URLENCODED );
135+ try {
136+ return MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_JSON )
137+ || MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_FORM_URLENCODED );
138+ } catch (InvalidMimeTypeException e ) {
139+ return false ;
140+ }
136141 }
137142
138143 static final class RequestBodyExtractingEventProcessor implements EventProcessor {
Original file line number Diff line number Diff line change @@ -266,6 +266,12 @@ class SentrySpringFilterTest {
266266 body = " x" .repeat(10001 ),
267267 expectedToBeCached = false ,
268268 ),
269+ TestParams (
270+ maxRequestBodySize = MEDIUM ,
271+ body = " xxx" ,
272+ expectedToBeCached = false ,
273+ contentType = " invalid" ,
274+ ),
269275 TestParams (
270276 maxRequestBodySize = ALWAYS ,
271277 body = " x" .repeat(10001 ),
Original file line number Diff line number Diff line change 2626import org .jetbrains .annotations .NotNull ;
2727import org .jetbrains .annotations .Nullable ;
2828import org .springframework .http .MediaType ;
29+ import org .springframework .util .InvalidMimeTypeException ;
2930import org .springframework .util .MimeType ;
3031import org .springframework .web .filter .OncePerRequestFilter ;
3132import org .springframework .web .util .ContentCachingRequestWrapper ;
@@ -131,8 +132,12 @@ && shouldCacheMimeType(contentType)
131132 }
132133
133134 private static boolean shouldCacheMimeType (String contentType ) {
134- return MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_JSON )
135- || MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_FORM_URLENCODED );
135+ try {
136+ return MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_JSON )
137+ || MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_FORM_URLENCODED );
138+ } catch (InvalidMimeTypeException e ) {
139+ return false ;
140+ }
136141 }
137142
138143 static final class RequestBodyExtractingEventProcessor implements EventProcessor {
Original file line number Diff line number Diff line change @@ -266,6 +266,12 @@ class SentrySpringFilterTest {
266266 body = " x" .repeat(10001 ),
267267 expectedToBeCached = false ,
268268 ),
269+ TestParams (
270+ maxRequestBodySize = MEDIUM ,
271+ body = " xxx" ,
272+ expectedToBeCached = false ,
273+ contentType = " invalid" ,
274+ ),
269275 TestParams (
270276 maxRequestBodySize = ALWAYS ,
271277 body = " x" .repeat(10001 ),
Original file line number Diff line number Diff line change 2626import org .jetbrains .annotations .NotNull ;
2727import org .jetbrains .annotations .Nullable ;
2828import org .springframework .http .MediaType ;
29+ import org .springframework .util .InvalidMimeTypeException ;
2930import org .springframework .util .MimeType ;
3031import org .springframework .web .filter .OncePerRequestFilter ;
3132import org .springframework .web .util .ContentCachingRequestWrapper ;
@@ -131,8 +132,12 @@ && shouldCacheMimeType(contentType)
131132 }
132133
133134 private static boolean shouldCacheMimeType (String contentType ) {
134- return MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_JSON )
135- || MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_FORM_URLENCODED );
135+ try {
136+ return MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_JSON )
137+ || MimeType .valueOf (contentType ).isCompatibleWith (MediaType .APPLICATION_FORM_URLENCODED );
138+ } catch (InvalidMimeTypeException e ) {
139+ return false ;
140+ }
136141 }
137142
138143 static final class RequestBodyExtractingEventProcessor implements EventProcessor {
Original file line number Diff line number Diff line change @@ -266,6 +266,12 @@ class SentrySpringFilterTest {
266266 body = " x" .repeat(10001 ),
267267 expectedToBeCached = false ,
268268 ),
269+ TestParams (
270+ maxRequestBodySize = MEDIUM ,
271+ body = " xxx" ,
272+ expectedToBeCached = false ,
273+ contentType = " invalid" ,
274+ ),
269275 TestParams (
270276 maxRequestBodySize = ALWAYS ,
271277 body = " x" .repeat(10001 ),
You can’t perform that action at this time.
0 commit comments