-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
MultipartWriter quotes field name wrong #4012
Comments
I noticed, the
RFC2388 is now obsoleted by the RFC7578. |
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
I checked with Firefox, and any form fields names containing "[]" are sent without being enoded. Also filenames are sent in 8-bit utf-8 without any encoding. Rereading #916, it would seem the quote_fields=False option has been added to get correct behavior. Any API expecting the default quote_fields=True behavior can not work with submissions from html forms. With my patch and quote_fields=False, it is further fixed to quote any quotes in the file names. |
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
…s#4031) Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
…s#4031) Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Posting form data with field names containing "[]" were not recognized by other multipart/form-data parsers. The percent-encoding is only to be used on the filename parameter that follows how of a "file:" URI may be encoded according to RFC7578.
Long story short
My client needs to send multipart/form-data to an API that expects field names with
[]
in the name. The server does not accept the submission with defaultset_content_disposition
parameters due to wrong quoting.Expected behaviour
Content-Disposition: form-data; name="files[]"; filename="filename"
Actual behaviour
Content-Disposition: form-data; name="files%5B%5D"; filename="filename"; filename*=utf-8''filename
Steps to reproduce
Client code is like
Your environment
aiohttp==3.5.4 async client, Ubuntu 18.04, python 3.6.8.
Analysis
Returning Values from Forms: multipart/form-data says
It would seem the current implementation misinterpreted this to mean all field values are to be percent-encoded. But the RFC7578 is clear that the encoding is only to be used on file names. Furthermore, the
filename*=
form from MIME Parameter Value and Encoded Word Extensions should be used only for the other fields, but as the filename is already via percent-encoding to within US-ASCII,filename*=
is not to be used on the filename.For converting from unicode string to bytes for the percent-encoding, user will need to specify charset in some cases, as in the RFC:
Thus, in some cases, an additional
charset
parameter is needed inset_content_disposition
. Is it needed in other functions?The RFCs refer to RFC822 for quoted-string definition, which is currently obsoleted by Internet Message Format RFC5322.
And from Augmented BNF for Syntax Specifications: ABNF
The quoted-pair quoting of quoted-string is missing in the current implementation.
There is also a rather far-fetched case of extremely long values causing the line length limit of 998 characters to be exceeded https://tools.ietf.org/html/rfc5322#section-2.1.1 and requiring using the Folding White Space (FWS).
I can not tell if there would be any compatibility impact of just changing the percent-quoting to the correct quoted-pair quoting. Should the
quote_fields
parameter concern the percent-encoding of filename or the quoted-pair of all fields?The current behavior seems to be result of discussion in #916 to fix #903.
The text was updated successfully, but these errors were encountered: