cpython icon indicating copy to clipboard operation
cpython copied to clipboard

bpo-36226: Fix multipart false positive header defects

Open grische opened this issue 6 years ago • 17 comments

The current implementation of multipart/related in urllib triggers header defects even though the headers are valid: [StartBoundaryNotFoundDefect(), MultipartInvariantViolationDefect()]

The example header is valid according to RFC 2387 (https://tools.ietf.org/html/rfc2387):

Content-Type: multipart/related; boundary="===" 

Both defects are triggered by the fact that httplib only passes on headers to the underlying email parser, while the email parser assumes to receive a full message. The simple fix is to tell the underlying email parser that we are only passing the header: https://github.com/python/cpython/commit/89285439c7f94a3e62cee3d15e343218903c2af8

The second issue is related, but independent: The underlying email parser checks if the parsed message is of type multipart by checking of the object "root" is of type list. As we only passed the header (and set headersonly=True), the check does makes no sense anymore at this point, creating a false positive: https://github.com/python/cpython/pull/12214/commits/a82e662ab3339072d7b86a8090989fba60ef9c37

This issue has been a while with python (backport to 3.7 easily possible) and can also be found in urllib3 (hence also requests, etc):

  • https://stackoverflow.com/questions/49338811/does-requests-properly-support-multipart-responses
  • https://github.com/urllib3/urllib3/issues/800

https://bugs.python.org/issue36226

grische avatar Mar 07 '19 16:03 grische

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

the-knights-who-say-ni avatar Mar 07 '19 16:03 the-knights-who-say-ni

@grische, thank you for your interest in contributing to CPython. In order to have someone review your change, you'll need to sign the Contributor agreement. Thanks!

csabella avatar Jun 05 '19 16:06 csabella

Thanks for the PR, but closing as the CLA has not been signed within the last month. If you do decide to sign the CLA we can re-open this PR.

brettcannon avatar Aug 08 '19 23:08 brettcannon

@brettcannon the CLA has been signed a long time ago, but the system doesn't show the results. Your legal team has been informed and should be aware of the issue.

grische avatar Aug 08 '19 23:08 grische

@grische not sure who you emailed but you should email [email protected] to find out what's going on with your CLA.

brettcannon avatar Aug 09 '19 21:08 brettcannon

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

bedevere-bot avatar Sep 05 '19 01:09 bedevere-bot

I added the news entries for both commits, as they are fixing different parts.

I have made the requested changes; please review again

grische avatar Sep 05 '19 10:09 grische

Thanks for making the requested changes!

@maxking: please review the changes made to this pull request.

bedevere-bot avatar Sep 05 '19 10:09 bedevere-bot

Catching up on 4 years of conversations on b.p.o, this issue is way more complicated than it looks :)

Most of the context (and one another associated patch) is present in https://bugs.python.org/issue24363, https://bugs.python.org/issue29353. Martin Panter thinks using headersonly can cause problems when trying to convert it back to string

Parser().parsestr("Content-Type: message/delivery-status\r\nInvalid line\r\n\r\n", headersonly=True).as_string()

See bpo-29353 has context on this side effect of using headersonly.

maxking avatar Sep 14 '19 18:09 maxking

@maxking Thanks for digging into that.

I am aware that there are more issues in the parser. However, I am confident that my patches are on the right track to improve the situation without breaking backwards compatibility, as I didn't observe any failing tests.

It seems that you are taking care of the outstanding (and related) issues on bpo-24363? It would be good to have these sorted as well.

Regarding the as_string conversion, I agree to David Murray, that the lack of tests for this conversion seems like it is not an expected use-case and hence does not seem like a hard blocker to get this PR merged?

grische avatar Sep 16 '19 10:09 grische

@maxking are there any further changes you are requesting?

grische avatar Sep 25 '19 08:09 grische

@maxking ping

grische avatar Jan 20 '20 15:01 grische

This PR is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jun 15 '25 00:06 github-actions[bot]

@maxking ping

grische avatar Jun 15 '25 06:06 grische

This PR is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jan 01 '26 06:01 github-actions[bot]

Still an issue

fadenb avatar Jan 01 '26 08:01 fadenb

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

bedevere-app[bot] avatar Jan 01 '26 18:01 bedevere-app[bot]