8000 [2.7] bpo-30458: Disallow control chars in http URLs. (GH-12755) (GH-13154) by vstinner · Pull Request #13315 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[2.7] bpo-30458: Disallow control chars in http URLs. (GH-12755) (GH-13154) #13315

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

Merged
merged 2 commits into from
May 21, 2019
Merged

[2.7] bpo-30458: Disallow control chars in http URLs. (GH-12755) (GH-13154) #13315

merged 2 commits into from
May 21, 2019

Conversation

vstinner
Copy link
Member
@vstinner vstinner commented May 14, 2019

Disallow control chars in http URLs in urllib2.urlopen. This
addresses a potential security problem for applications that do not
sanity check their URLs where http request headers could be injected.

Disable https related urllib tests on a build without ssl (GH-13032)
These tests require an SSL enabled build. Skip these tests when
python is built without SSL to fix test failures.

Use httplib.InvalidURL instead of ValueError as the new error case's
exception. (GH-13044)

Backport Co-Authored-By: Miro Hrončok miro@hroncok.cz

(cherry picked from commit 7e200e0)

Notes on backport to Python 2.7:

  • test_urllib tests urllib.urlopen() which quotes the URL and so is
    not vulerable to HTTP Header Injection.
  • Add tests to test_urllib2 on urllib2.urlopen().
  • Reject non-ASCII characters: range 0x80-0xff.

https://bugs.python.org/issue30458

Disallow control chars in http URLs in urllib2.urlopen.  This
addresses a potential security problem for applications that do not
sanity check their URLs where http request headers could be injected.

Disable https related urllib tests on a build without ssl (GH-13032)
These tests require an SSL enabled build. Skip these tests when
python is built without SSL to fix test failures.

Use httplib.InvalidURL instead of ValueError as the new error case's
exception. (GH-13044)

Backport Co-Authored-By: Miro Hrončok <miro@hroncok.cz>

(cherry picked from commit 7e200e0)

Notes on backport to Python 2.7:

* test_urllib tests urllib.urlopen() which quotes the URL and so is
  not vulerable to HTTP Header Injection.
* Add tests to test_urllib2 on urllib2.urlopen().
* Reject non-ASCII characters: range 0x80-0xff.
@vstinner vstinner added the type-security A security issue label May 14, 2019
@bedevere-bot bedevere-bot added the type-bug An unexpected behavior, bug, or error label May 14, 2019
@vstinner
Copy link
Member Author

I backported the fix from Python 3.7 to Python 2.7.

Please review it carefully, I had to make multiple changes to adapt the fix to Python 2:

  • non-ASCII characters are explicitly rejected
  • urllib doesn't reject control characters: they are quoted properly, so I addapted test_urllib
  • urllib2 doesn't quote the URL and so reject control characters, I added tests to test_urllib2
  • I replaced http.client with httplib
  • I replaced urllib.request with urllib or urllib2

@vstinner vstinner requested a review from gpshead May 14, 2019 15:09
@vstinner
Copy link
Member Author

@orsenthil @ned-deily @tirkarthi @hroncok: Wo 8000 uld you mind to review my backport to Python 2.7?

Copy link
Member
@tirkarthi tirkarthi left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@ned-deily
Copy link
Member
ned-deily commented May 15, 2019

@vstinner I'm not sure why you asked me to review this. Perhaps you meant to ask @benjaminp as 2.7. release manager?

@vstinner
Copy link
Member Author

@vstinner I'm not sure why you asked me to review this. Perhaps you mean 8000 t to ask @benjaminp as 2.7. release manager?

I just copied the list of all people who reviewed the change in other branches. If you have no opinion, that's fine :-)

I would prefer to have more eyes as possible on this tricky backport ;-)

Copy link
Member
@orsenthil orsenthil left a comment

Choose a reason for hiding this comment

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

lgtm. Thanks, Victor.

Copy link
Member
@gpshead gpshead left a comment

Choose a reason for hiding this comment

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

overall, this looks good to me, my only comments are minor.

@@ -257,6 +261,33 @@ def test_url_fragment(self):
finally:
self.unfakehttp()

@unittest.skipUnless(ssl, "ssl module required")
Copy link
Member

Choose a reason for hiding this comment

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

is this true for these tests? (not that it matters, all sane platforms have ssl so these tests will be run regardless)

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, no, the decorator is wrong: i removed it.

@vstinner vstinner merged commit bb8071a into python:2.7 May 21, 2019
@vstinner vstinner deleted the url-no-control-chars27 branch May 21, 2019 13:12
@vstinner
Copy link
Member Author

Ok, thanks everybody for reviews. I merged my PR.

jeff5 added a commit to jython/jython that referenced this pull request Mar 13, 2022
This change brings selected modules and tests from CPython 2.7.18 to our
lib-python. Where we have specialised versions for Jython, we
cherry-pick tests and code that relate to the CVE. We use the 2.7
back-port from CPython as a guide (python/cpython#13315).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error type-security A security issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0