Skip to content
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

Fix #4012 encoding of content-disposition parameters #4031

Merged
merged 1 commit into from
Nov 26, 2020

Conversation

kohtala
Copy link
Contributor

@kohtala kohtala commented Aug 31, 2019

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.

What do these changes do?

Only encode content-disposition filename parameter using percent-encoding.
Other parameters are encoded to quoted-string or RFC2231 extended parameter
value.

Are there changes in behavior for the user?

I do not know if there are some implementations that depend on the wrong encoding.

Related issue number

Related to #4012.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Aug 31, 2019
@codecov-io
Copy link

codecov-io commented Aug 31, 2019

Codecov Report

Merging #4031 (f26bded) into master (1879aa1) will decrease coverage by 0.01%.
The diff coverage is 93.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4031      +/-   ##
==========================================
- Coverage   97.54%   97.53%   -0.02%     
==========================================
  Files          43       43              
  Lines        8809     8798      -11     
  Branches     1415     1414       -1     
==========================================
- Hits         8593     8581      -12     
- Misses        101      103       +2     
+ Partials      115      114       -1     
Flag Coverage Δ
unit 97.41% <93.10%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiohttp/payload.py 95.32% <ø> (ø)
aiohttp/helpers.py 96.88% <93.10%> (+0.33%) ⬆️
aiohttp/cookiejar.py 98.78% <0.00%> (-0.39%) ⬇️
aiohttp/connector.py 96.48% <0.00%> (-0.32%) ⬇️
aiohttp/web_server.py 94.28% <0.00%> (-0.16%) ⬇️
aiohttp/pytest_plugin.py 97.45% <0.00%> (-0.05%) ⬇️
aiohttp/web_runner.py 97.76% <0.00%> (-0.01%) ⬇️
aiohttp/web.py 99.14% <0.00%> (-0.01%) ⬇️
aiohttp/abc.py 100.00% <0.00%> (ø)
aiohttp/resolver.py 93.18% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1879aa1...f26bded. Read the comment docs.

@asvetlov
Copy link
Member

asvetlov commented Sep 6, 2019

@kxepal would you review?

qval = quote(val, '') if quote_fields else val
lparams.append((key, '"%s"' % qval))
if key == 'filename':
lparams.append(('filename*', "utf-8''" + qval))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is correct. filename* must be added if filename is not ASCII-only per RFC 6266, appendix D. The logic is supposed to be roughly https://github.com/cherrypy/cherrypy/pull/1851/files#diff-9d544371f1a0e2079e68ac3cca04bc6cd1ccaf92797f378b285f307871b8d6f0R32-R53. Note that NFKC is supposed to be used for normalization.

Copy link
Member

Choose a reason for hiding this comment

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

Looking closer, it seems you may be right about the newer RFC...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi. As this is the payload and not http Content-Disposition header, filename* can not be used. I believe your link was about the http header.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, then I misread what you're doing here.

@CLAassistant

This comment has been minimized.

@kohtala
Copy link
Contributor Author

kohtala commented Nov 23, 2020

I rebased the commit on top of current master. I do not see the macos failure related to this PR.

What is the CLA message? The link says

Error
There is no CLA to sign for aio-libs/aiohttp
(could not find linked item for owner aio-libs and repo aiohttp)

@asvetlov
Copy link
Member

Please ignore the CLA, I've switched it off back -- and forever.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

LGTM.
Thank you!

I'd like to get an additional review from aiohttp team, otherwise I'll merge this PR in a week.
It will be a part of aiohttp 3.8

tests/test_helpers.py Outdated Show resolved Hide resolved
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.
@asvetlov asvetlov merged commit aa11d78 into aio-libs:master Nov 26, 2020
@asvetlov
Copy link
Member

Thanks!

@aio-libs-github-bot
Copy link
Contributor

💔 Backport was not successful

The PR was attempted backported to the following branches:

  • ❌ 3.8: Commit could not be cherrypicked due to conflicts

commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
…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.
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
…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.
asvetlov pushed a commit that referenced this pull request Oct 24, 2021
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.
@patchback
Copy link
Contributor

patchback bot commented Oct 31, 2021

Backport to 3.8: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply aa11d78 on top of patchback/backports/3.8/aa11d78356e243be985f1d2a30f733d95417cf08/pr-4031

Backporting merged PR #4031 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/aio-libs/aiohttp.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/3.8/aa11d78356e243be985f1d2a30f733d95417cf08/pr-4031 upstream/3.8
  4. Now, cherry-pick PR Fix #4012 encoding of content-disposition parameters #4031 contents into that branch:
    $ git cherry-pick -x aa11d78356e243be985f1d2a30f733d95417cf08
    If it'll yell at you with something like fatal: Commit aa11d78356e243be985f1d2a30f733d95417cf08 is a merge but no -m option was given., add -m 1 as follows intead:
    $ git cherry-pick -m1 -x aa11d78356e243be985f1d2a30f733d95417cf08
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Fix #4012 encoding of content-disposition parameters #4031 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.8/aa11d78356e243be985f1d2a30f733d95417cf08/pr-4031
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

remram44 added a commit to remram44/taguette that referenced this pull request Nov 3, 2021
aiohttp now percent-encodes filenames, causing a test to fail.

aio-libs/aiohttp#4031
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants