Skip to content

Commit 3724d79

Browse files
committed
fix: handle unparseable mime-type
1 parent fc5ccaf commit 3724d79

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.jetbrains.annotations.NotNull;
2727
import org.jetbrains.annotations.Nullable;
2828
import org.springframework.http.MediaType;
29+
import org.springframework.util.InvalidMimeTypeException;
2930
import org.springframework.util.MimeType;
3031
import org.springframework.web.filter.OncePerRequestFilter;
3132
import 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 {

sentry-spring/src/test/kotlin/io/sentry/spring/SentrySpringFilterTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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),

0 commit comments

Comments
 (0)