Skip to content

Spring Web should process requests with empty/invalid mime type [SPR-14309] #18881

Closed
@spring-projects-issues

Description

@spring-projects-issues

Nazar Vishka opened SPR-14309 and commented

If a client is sending a POST message with an empty/invalid header 'Content-Type' the request fails with InvalidMediaTypeException.

org.springframework.http.InvalidMediaTypeException: Invalid mime type "null": does not contain '/'
        at org.springframework.http.MediaType.parseMediaType(MediaType.java:385) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:722) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.http.server.ServletServerHttpRequest.getHeaders(ServletServerHttpRequest.java:116) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:810) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:71) ~[spring-web-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.servlet.handler.AbstractHandlerMapping$CorsInterceptor.preHandle(AbstractHandlerMapping.java:503) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968) [spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:870) [spring-webmvc-4.2.5.RELEASE.jar!/:4.2.5.RELEASE]

I think that org.springframework.http.HttpHeaders#getContentType should handle InvalidMediaTypeException exception and return null in such cases or you should change behaviour of org.springframework.http.MediaType#parseMediaType


Affects: 4.2.6

Issue Links:

Backported to: 4.2.7

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions