Multipart boundary should strip quotes
See original GitHub issueAffects: 5.3.3
Library: spring-web
Although uncommon, some HTTP clients will quote the multipart boundary value. This does appear to be acceptable based on a reading of the RFC. As a specific example, the .NET SDK’s HttpClient
class will generate a quoted UUID to use as the boundary:
POST /foo HTTP/1.1
Content-Type: multipart/form-data; boundary="7e296554-91ca-4075-ada1-c72043296dd7"
Host: foo.bar.example
Content-Length: <snip>
Expect: 100-continue
--7e296554-91ca-4075-ada1-c72043296dd7
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=Foo
BAR
--7e296554-91ca-4075-ada1-c72043296dd7--
The problem is the codec shipped with spring-web
does not handle this case:
@Nullable
private static byte[] boundary(HttpMessage message) {
MediaType contentType = message.getHeaders().getContentType();
if (contentType != null) {
String boundary = contentType.getParameter("boundary");
if (boundary != null) {
return boundary.getBytes(StandardCharsets.ISO_8859_1);
}
}
return null;
}
The code should check the boundary
string to see if it starts and ends with an ASCII double-quote ("
). If so, it should strip them before creating the byte array to be used later.
See https://github.com/spring-projects/spring-framework/issues/26615 which led to me discovering this issue.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
HttpContent boundary double quotes - Stack Overflow
You can remove the quotes from the boundary by using the following code: var boundary = formData.Headers.ContentType.Parameters.First(o => o.
Read more >Problems with WebApi, Multipart Content Upload and ...
After the content is created I will simply remove quotes in the boundary value. Posted Sep 10 2013, 05:11 PM by Damir Dobric....
Read more >RFC1341(MIME) : 7 The Multipart content type
The body must then contain one or more "body parts," each preceded by an encapsulation boundary, and the last one followed by a...
Read more >PI61450: APACHE WINK CODE DOES NOT REMOVE ... - IBM
There is a problem with the way the Apache Wink code parses the boundary value. The code should strip any leading and trailing...
Read more >Multipart (Form Data) Format - MuleSoft Documentation
To distinguish the beginning and end of a part, a boundary is used and metadata for each part can be added through headers....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think it’s out already, see https://repo.spring.io/snapshot/org/springframework/spring/5.3.5-SNAPSHOT/
@poutsma Thank you! When do you think a new
SNAPSHOT
build will go out for the library? I’m comfortable adding the Spring snapshot repos in the short term to get this fix into my application.