10000 mime: use percent-escaping for multipart form field and file names. by monnerat · Pull Request #7805 · curl/curl · GitHub
[go: up one dir, main page]

Skip to content

mime: use percent-escaping for multipart form field and file names. #7805

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

Closed
wants to merge 1 commit into from

Conversation

monnerat
Copy link
Contributor
@monnerat monnerat commented Oct 1, 2021

Until now, form field and file names where escaped using the
backslash-escaping algorithm defined for multipart mails. This commit
replaces this with the percent-escaping method for URLs.

As this may introduce incompatibilities with server-side applications,
a libcurl option CURLOPT_FORM_ESCAPE_AS_MIME is introduced to revert to
legacy use of backslash-escaping. This is controlled by new cli tool
option --mime-escape.

New tests and documentation are provided for this feature.

Reported by: Ryan Sleevi
Fixes #7789

Copy link
Member
@bagder bagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice take!

@bagder bagder added the HTTP label Oct 1, 2021
@monnerat monnerat force-pushed the formdata branch 2 times, most recently from 51a81f7 to 49c7329 Compare October 2, 2021 22:34
Example: --form-escape --form 'field\\name=curl' 'file=@load"this' $URL
---
Tells curl to escape multipart form field and file names using the
backslash-escaping algorithm rather than the percent-encoding.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Tells curl to pass on multipart form fields and file names using backslash-escaping instead of percent-encoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that having a plural for fields references the contents rather than their names. What about fields- and file names ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to:

Tells curl to pass on names of multipart form fields and files using backslash-escaping instead of percent-encoding.

@monnerat monnerat force-pushed the formdata branch 2 times, most recently from e1b4805 to c84699e Compare October 7, 2021 08:37
@monnerat monnerat requested a review from bagder October 7, 2021 11:29
@monnerat
Copy link
Contributor Author
monnerat commented Oct 8, 2021

Changed the escaping algorithm: this is shorter, simpler and saves a call to Curl_convert_to_network on non-ascii platforms.

@bagder bagder added the feature-window A merge of this requires an open feature window label Oct 14, 2021
@monnerat monnerat force-pushed the formdata branch 2 times, most recently from 4e05192 to e4acb7a Compare October 21, 2021 14:42
Help: Escape multipart form field/file names using backslash
Protocols: HTTP
See-also: form
Added: 7.80.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems likely to end up landing in 7.81.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All version references changed to 7.81.0 now.

Until now, form field and file names where escaped using the
backslash-escaping algorithm defined for multipart mails. This commit
replaces this with the percent-escaping method for URLs.

As this may introduce incompatibilities with server-side applications,
a new libcurl option CURLOPT_MIME_OPTIONS with bitmask
CURLMIMEOPT_FORMESCAPE is introduced to revert to legacy use of
backslash-escaping. This is controlled by new cli tool option --form-escape.

New tests and documentation are provided for this feature.

Reported by: Ryan Sleevi
Fixes curl#7789
@bagder bagder removed the feature-window A merge of this requires an open feature window label Nov 15, 2021
@bagder bagder closed this in b20b364 Nov 15, 2021
@bagder
Copy link
Member
bagder commented Nov 15, 2021

Thanks!

@monnerat
Copy link
Contributor Author

Thanks for pulling!

fabpot added a commit to symfony/symfony that referenced this pull request Dec 20, 2021
…las-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Mime] Fix encoding filenames in multipart/form-data

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #41249
| License       | MIT
| Doc PR        | -

File uploads that use forms have stick to browsers' behavior. This is captured in the WHATWG in their living standard:
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data

curl did the same a few weeks ago:
curl/curl#7805

Commits
-------

a58c342 [Mime] Fix encoding filenames in multipart/form-data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Inconsistent/Incompatible handling of filename escaping in multipart/form-data compared to RFC 7578 and browsers
2 participants
0