Invalid multipart/form-data query causes 500 instead of 400
curl -v -H 'x-api-key: tgpak_nyaaaaaaa...' -H 'content-type: multipart/form-data' -d 'zzz' https://app.tolgee.io/v2/projects/import
2022-09-24 13:07:25.128 ERROR 1 --- [nio-8080-exec-6] io.tolgee.ExceptionHandlers : org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.handleParseFailure(StandardMultipartHttpServletRequest.java:127)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:115)
at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.<init>(StandardMultipartHttpServletRequest.java:88)
at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:122)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1208)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1042)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
(...)
Caused by: java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
at org.apache.catalina.connector.Request.parseParts(Request.java:2977)
(...)
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
at org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl.init(FileItemIteratorImpl.java:189)
(...)
Here are a few more cases triggering a 500 instead of a 400 Bad Request:
- Using
\ninstead of\r\n(and other forms of invalid multipart data) - Not having a
filesin the payload- Note: items without a
filenameare skipped and as such having only filename-less data infilesdoes run into this scenaro
- Note: items without a
Here are some test payloads I used that might be useful for writing tests
content-type: multipart/form-data; boundary=boundawy
--boundawy
Content-Disposition: form-data; name="nya"
{"meow":"miaou"}
--boundawy--
--boundawy
Content-Disposition: form-data; name="files"
{"meow":"miaou"}
--boundawy--
--boundawy
Content-Disposition: form-data; name="files"; filename="fr-FR.json"
{"meow":"miaou"}
Would it make sense to add MultipartException handler to ExceptionHandlers returning some generic error, or do you think we should also provide some describing error messages as well?
The existing message is descriptive enough of the error I think. For incomplete requests (with missing fields), the message contains information about the fields that are missing which is valuable information.
That being said, for incomplete data it may be better to return STANDARD_VALIDATION: { ... } stuff like the other endpoints.
Will look into it.
This issue is stale because it has been open for 30 days with no activity.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.