-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Bug]: Boundary is not extracted correctly from multipart/form-data requests when using CapacitorHttp #7621
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as abuse.
This comment was marked as abuse.
Hey, My team is waiting too for this update. Any information about when we can expect this update on production? |
I'm also having the same issue. |
This comment was marked as abuse.
This comment was marked as abuse.
That I think is the tagging, it may even be automated. Try to avoid tagging Julio and I, but this is on our radar for sure, but I cannot get a definitive date for you right now. |
For anyone who is really blocked by this, you might consider patching the plugin following this guide here, for example: https://capawesome.io/blog/how-to-patch-a-capacitor-plugin/. You just need to adapt two files according to my PR #7518:
I know this is kind of a hacky solution, but on the other hand, we have been using the patched version in production code for a few months now with success. Still, it would be great to have this verified by the Capacitor team, as it's entirely possible that I missed something with my changes. |
Capacitor Version
The extraction of the value of the boundary of multipart/form-data requests fails for some requests due to the value being surrounded by double quotes, which is allowed and happens occasionally (See MDN Reference which utilizes double quotes for the boundary in their example: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST#example). The current implementation only works with no surroundings of the boundary value and otherwise just includes them in the actual request body which will then fail on the server side where the serve will not be able to parse the request body.
In addition to that, the whole extraction currently just uses the last key of the Content-Type header which might not necessarily be the boundary but could also be something such as
charset
(see example implementation or MDN reference).Other API Details
No response
Platforms Affected
Current Behavior
Let's consider the following request (assuming CapacitorHttp is active)
Because of CapacitorHttp is currently taking the last key of the Content-Type header as boundary the actual request body sent by CapacitorHttp will then look like:
The same request without the additional
charset
key but enclosed in double quotes: ('Content-Type': 'multipart/form-data; boundary="boundary"'
) will look like this:The server will however read the boundary without quotes from the header and thus will be unable to parse the body.
Expected Behavior
For both cases the request body should look like this:
Project Reproduction
https://github.com/michaelwolz/multipart-form-data-not-working-on-ios
Additional Information
(Non-)working example can be found here: https://github.com/michaelwolz/multipart-form-data-not-working-on-ios/blob/master/src/js/capacitor-welcome.js#L76-L94
You install the current official version and it'll fail while working with the provided fix.
Pull-Request fixing the problem by accepting arbitrary position of the boundary and ignoring quotes: #7518
Fairly sure that the described behavior is also the origin of the following issues:
multipart/form-data
#7579The text was updated successfully, but these errors were encountered: