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

bpo-43882 - urllib.parse should sanitize urls containing ASCII newline and tabs. #25595

Merged
merged 10 commits into from Apr 29, 2021

Conversation

orsenthil
Copy link
Member

@orsenthil orsenthil commented Apr 25, 2021

bpo-43882: Strip ascii newline and tabs from the url input, following WHATWG specification

Presence newline or tab characters in URL allowed attackers to write scripts in URL, hijack the web-server.

Following the controlling specification for URLs defined by WHATWG urllib.parse strips ASCII newline and tabs from the url, preventing such attacks.

https://bugs.python.org/issue43882

@orsenthil orsenthil changed the title issue43882 - urllib.parse should sanitize urls containing ASCII newline and tabs. bpo-43882 - urllib.parse should sanitize urls containing ASCII newline and tabs. Apr 25, 2021
@orsenthil orsenthil self-assigned this Apr 25, 2021
Copy link
Member

@gpshead gpshead left a comment

Some code suggestions made.

Lib/test/test_urlparse.py Outdated Show resolved Hide resolved
Lib/urllib/parse.py Outdated Show resolved Hide resolved
Doc/library/urllib.parse.rst Outdated Show resolved Hide resolved
Doc/library/urllib.parse.rst Outdated Show resolved Hide resolved
@bedevere-bot
Copy link

bedevere-bot commented Apr 28, 2021

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@gpshead gpshead added type-bug An unexpected behavior, bug, or error type-security A security issue labels Apr 28, 2021
Lib/urllib/parse.py Outdated Show resolved Hide resolved
@orsenthil orsenthil requested review from gpshead and tirkarthi Apr 28, 2021
Doc/library/urllib.parse.rst Outdated Show resolved Hide resolved
Doc/library/urllib.parse.rst Outdated Show resolved Hide resolved
orsenthil and others added 5 commits Apr 29, 2021
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
….rst

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@miss-islington
Copy link
Contributor

miss-islington commented Apr 29, 2021

Thanks @orsenthil for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7, 3.8, 3.9.
🐍🍒🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 29, 2021
…e and tabs. (pythonGH-25595)

* issue43882 - urllib.parse should sanitize urls containing ASCII newline and tabs.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)

Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
@bedevere-bot
Copy link

bedevere-bot commented Apr 29, 2021

GH-25725 is a backport of this pull request to the 3.9 branch.

@bedevere-bot
Copy link

bedevere-bot commented Apr 29, 2021

GH-25726 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 29, 2021
…e and tabs. (pythonGH-25595)

* issue43882 - urllib.parse should sanitize urls containing ASCII newline and tabs.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)

Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
@bedevere-bot
Copy link

bedevere-bot commented Apr 29, 2021

GH-25727 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 29, 2021
…e and tabs. (pythonGH-25595)

* issue43882 - urllib.parse should sanitize urls containing ASCII newline and tabs.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)

Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
@bedevere-bot
Copy link

bedevere-bot commented Apr 29, 2021

GH-25728 is a backport of this pull request to the 3.6 branch.

orsenthil added a commit that referenced this pull request Apr 29, 2021
…newline and tabs. (GH-25595) (GH-25725)

* bpo-43882 - urllib.parse should sanitize urls containing ASCII newline and tabs. (GH-25595)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)
Co-authored-by: Senthil Kumaran <skumaran@gatech.edu>
orsenthil added a commit to orsenthil/cpython that referenced this pull request Apr 30, 2021
…e and tabs. (pythonGH-25595)

* issue43882 - urllib.parse should sanitize urls containing ASCII newline and tabs.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)

Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
kreathon pushed a commit to kreathon/cpython that referenced this pull request May 2, 2021
…e and tabs. (pythonGH-25595)

* issue43882 - urllib.parse should sanitize urls containing ASCII newline and tabs.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
gentoo-bot pushed a commit to gentoo/cpython that referenced this pull request May 2, 2021
…newline and tabs. (pythonGH-25595) (pythonGH-25725)

* bpo-43882 - urllib.parse should sanitize urls containing ASCII newline and tabs. (pythonGH-25595)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)
Co-authored-by: Senthil Kumaran <skumaran@gatech.edu>
(backported to Python 2.7 by Michał Górny)
ambv pushed a commit that referenced this pull request May 5, 2021
…newline and tabs. (GH-25595) (#25726)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)
Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
Co-authored-by: Senthil Kumaran <skumaran@gatech.edu>
miss-islington added a commit to miss-islington/cpython that referenced this pull request May 5, 2021
…newline and tabs. (pythonGH-25595) (pythonGH-25726)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)
Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
Co-authored-by: Senthil Kumaran <skumaran@gatech.edu>
(cherry picked from commit 515a7bc)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
miss-islington added a commit to miss-islington/cpython that referenced this pull request May 5, 2021
…newline and tabs. (pythonGH-25595) (pythonGH-25726)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 76cd81d)
Co-authored-by: Senthil Kumaran <senthil@uthcode.com>
Co-authored-by: Senthil Kumaran <skumaran@gatech.edu>
(cherry picked from commit 515a7bc)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
@bedevere-bot
Copy link

bedevere-bot commented May 5, 2021

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Gentoo Installed with X 3.8 has failed when building commit 515a7bc.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/291/builds/26) and take a look at the build logs.
  4. Check if the failure is related to this commit (515a7bc) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/291/builds/26

Failed tests:

  • test_socket

Failed subtests:

  • testSendFrame - test.test_socket.CANTest

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

410 tests OK.

1 test failed:
test_socket

12 tests skipped:
test_asdl_parser test_clinic test_devpoll test_gdb test_ioctl
test_kqueue test_msilib test_startfile test_winconsoleio
test_winreg test_winsound test_zipfile64

1 re-run test:
test_socket

Total duration: 27 min 39 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.8.ware-gentoo-x86.installed/build/target/lib/python3.8/test/test_socket.py", line 1957, in testSendFrame
    self.assertEqual(addr[1], socket.AF_CAN)
IndexError: tuple index out of range

@bedevere-bot
Copy link

bedevere-bot commented May 5, 2021

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86 Gentoo Non-Debug with X 3.8 has failed when building commit 515a7bc.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/324/builds/26) and take a look at the build logs.
  4. Check if the failure is related to this commit (515a7bc) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/324/builds/26

Failed tests:

  • test_socket

Failed subtests:

  • testSendFrame - test.test_socket.CANTest

Summary of the results of the build (if available):

== Tests result: FAILURE then FAILURE ==

413 tests OK.

10 slowest tests:

  • test_multiprocessing_spawn: 4 min 18 sec
  • test_concurrent_futures: 3 min 51 sec
  • test_tokenize: 3 min 13 sec
  • test_tools: 2 min 59 sec
  • test_asyncio: 2 min 52 sec
  • test_lib2to3: 2 min 33 sec
  • test_multiprocessing_forkserver: 1 min 49 sec
  • test_multiprocessing_fork: 1 min 38 sec
  • test_pickle: 1 min 10 sec
  • test_subprocess: 1 min 2 sec

1 test failed:
test_socket

9 tests skipped:
test_devpoll test_ioctl test_kqueue test_msilib test_startfile
test_winconsoleio test_winreg test_winsound test_zipfile64

1 re-run test:
test_socket

Total duration: 29 min 34 sec

Click to see traceback logs
Traceback (most recent call last):
  File "/buildbot/buildarea/cpython/3.8.ware-gentoo-x86.nondebug/build/Lib/test/test_socket.py", line 1957, in testSendFrame
    self.assertEqual(addr[1], socket.AF_CAN)
IndexError: tuple index out of range

slozier pushed a commit to IronLanguages/ironpython2 that referenced this pull request Feb 26, 2022
Implement the fix from the upstream python/cpython#25595
PhilGrayson added a commit to PhilGrayson/cob that referenced this pull request Jun 15, 2022
urlsplit was changed to strip ASCII newline and tab characters in
python/cpython#25595.

The urlsplit change breaks cob as it was relying on urlsplit to keep a
trailing newline character. This patch is backward compatible.

This issue was identified on Amazon Linux 2's Python distribution.
https://alas.aws.amazon.com/AL2/ALAS-2022-1802.html.

urlsplit behaviour before the fix.
```
Python 2.7.18 (default, Jun 10 2021, 00:11:02)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urlparse import urlsplit
>>> urlsplit("http://localhost/some-path\n").path
'/some-path\n'
>>>
```

urlsplit behaviour after the fix.
```
Python 2.7.18 (default, May 25 2022, 14:30:51)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urlparse import urlsplit
>>> urlsplit("http://localhost/some-path\n").path
'/some-path'
>>>
```
PhilGrayson added a commit to PhilGrayson/cob that referenced this pull request Jun 15, 2022
urlsplit function was changed to strip ASCII newline and tab characters
in python/cpython#25595.

The change breaks S3 authentication as cob was relying on urlsplit to keep
a trailing newline character.

This issue was identified on Amazon Linux 2 Python distribution which
backported the change to Python 2.
https://alas.aws.amazon.com/AL2/ALAS-2022-1802.html.

urlsplit behaviour before the fix.
```
Python 2.7.18 (default, Jun 10 2021, 00:11:02)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urlparse import urlsplit
>>> urlsplit("http://localhost/some-path\n").path
'/some-path\n'
>>>
```

urlsplit behaviour after the fix.
```
Python 2.7.18 (default, May 25 2022, 14:30:51)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urlparse import urlsplit
>>> urlsplit("http://localhost/some-path\n").path
'/some-path'
>>>
```
PhilGrayson added a commit to PhilGrayson/cob that referenced this pull request Jun 15, 2022
urlsplit function was changed to strip ASCII newline and tab characters
in python/cpython#25595.

The change causes this plugin to not properly authenticate with S3, since
a required newline character is no longer present.

This issue was identified on Amazon Linux 2 Python distribution which
backported the change to Python 2.
https://alas.aws.amazon.com/AL2/ALAS-2022-1802.html.

urlsplit behaviour before the fix.
```
Python 2.7.18 (default, Jun 10 2021, 00:11:02)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urlparse import urlsplit
>>> urlsplit("http://localhost/some-path\n").path
'/some-path\n'
>>>
```

urlsplit behaviour after the fix.
```
Python 2.7.18 (default, May 25 2022, 14:30:51)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urlparse import urlsplit
>>> urlsplit("http://localhost/some-path\n").path
'/some-path'
>>>
```
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.

None yet

7 participants