-
-
Notifications
You must be signed in to change notification settings - Fork 464
fix: handle unparseable mime-type #4939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| private static boolean shouldCacheMimeType(String contentType) { | ||
| return MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_JSON) | ||
| || MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED); | ||
| try { | ||
| return MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_JSON) | ||
| || MimeType.valueOf(contentType).isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED); | ||
| } catch (InvalidMimeTypeException e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| static final class RequestBodyExtractingEventProcessor implements EventProcessor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The sentry-spring-jakarta module's shouldCacheMimeType() method lacks InvalidMimeTypeException handling for invalid Content-Type headers.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The sentry-spring-jakarta module's shouldCacheMimeType() method in sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java lacks proper exception handling. When applications using this module with sentry.max-request-body-size defined receive requests with invalid Content-Type headers (e.g., Content-Type: invalid), MimeType.valueOf(contentType) throws an InvalidMimeTypeException. This unhandled exception causes the application to crash with a 500 error, preventing the request from proceeding through the filter pipeline.
💡 Suggested Fix
Wrap the shouldCacheMimeType() method in sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java with a try-catch block for InvalidMimeTypeException, matching the fix applied to other modules.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java#L132-L143
Potential issue: The `sentry-spring-jakarta` module's `shouldCacheMimeType()` method in
`sentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/SentrySpringFilter.java`
lacks proper exception handling. When applications using this module with
`sentry.max-request-body-size` defined receive requests with invalid `Content-Type`
headers (e.g., `Content-Type: invalid`), `MimeType.valueOf(contentType)` throws an
`InvalidMimeTypeException`. This unhandled exception causes the application to crash
with a 500 error, preventing the request from proceeding through the filter pipeline.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 4294118
📜 Description
Caught this one in production in one of our apps
Which we could easily replicate by sending a request with a
Content-Type: invalid(which is indeed an invalid mime-type). The app returns a 500 error.💡 Motivation and Context
This shouldn't cause an exception on the filter, determining if the content-type of the body is an acceptable one should not be handled by the Sentry request filter.
💚 How did you test it?
Create a minimal app Spring Boot MVC app with a
sentry.max-request-body-sizeproperty defined. Includesentry-spring-boot-starter-jakartaand send a request:See that a 500 error is returned. Re-run with this change and see that the request now goes through the remainder of the filter pipeline.
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps