You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
urllib.parse space handling CVE-2023-24329 appears unfixed #102153
Everyone (including the submitter of the now public exploit who submitted the issue half a year ago to security@python.org and the NVD) seems to think that #99421 "accidently fixed" CVE-2023-24329.
Did the Python Security Response Team verify that this vulnerability that was reported to them and that is now public was fixed by #99421?
The PoC from the submitter still works for me with the Debian package 3.11.2-4, which surprised me and makes me wonder whether the fix had any effect at all on the stripping of leading blanks issue in the CVE.
Maybe it's worth taking a step back and looking at the problem in a wider context.
In the PoC, the vulnerability arises not because parse() returns the wrong answer, but because it interprets the url differently from urlopen(). If they were both wrong in the same way it would be harmless. Why is there more than one piece of code which parses URLs? The DRY principle should apply.
Closely related, note that urlparse() does not have a vulnerability at all - any vulnerability is in code which relies on it and does so in a way in which it creates a vulnerability. In the PoC, the vulnerability is in the code for safeURLOpener().
The way in which urlparse() is implemented is fragile and bug prone. As a general principle, parsing code should not look ahead for known delimiters, it should systematically work from the start, advancing over characters tested to be legitimate. So urlparse('example.com@!$%^&*()_+-={}[]:;"\\|?query#frag')
should stop parsing at the '%' as that is not a legal character when not followed by two hex digits. It may return that "example.com@!$" is the path and there are extra characters after the URL (this style of parsing is often convenient when parsing items which may contain things to be parsed), or report failure due to an invalid URL. Instead, an early stage of processing skips ahead to the '?' and '#', so it claims there is a path, query, and fragment. While it could then validate these pieces and realise that the path is invalid, this can be forgotten and makes it unnecessarily difficult and dangerous to make the parser accept a valid URL followed by other characters (because it would need to reliably undo any parsing of anything past the valid part).
We will backport something that makes sense if we determine this is a security issue, that's why I duped the other issue here. Backporting the existing commit further does not make sense to me until the leading space issue, if present as reported here, is resolved. (I haven't taken the time to look. this is not an emergency)
I tested it and the problem doesn't seem to be fixed. I execute urlparse(" https://example.com"), the output before and after merging #99421 is the same.
Activity
ned-deily commentedon Feb 23, 2023
@pablogsal
pablogsal commentedon Feb 24, 2023
The backport was merged here #99446 no?
AdrianBunk commentedon Feb 24, 2023
@pablogsal #99446 is a backport of #99421 that does not seem to fix CVE-2023-24329:
pablogsal commentedon Feb 24, 2023
CC: @gpshead
arhadthedev commentedon Feb 27, 2023
CharlieZhao95 commentedon Feb 28, 2023
BTW, does this patch (CVE-2023-24329) require a backport to 3.10, 3.9 and older branches?
I noticed that the bug is currently only backported to the 3.11 branch, but it actually affects all versions prior to 3.11.
RSAlderman commentedon Feb 28, 2023
@CharlieZhao95 that's what I was asking for in #102293 - backport of the security vulnerability fix for CVE-2023-24329 to all in-service releases (3.7-3.10).
The request for the backports has been closed as a duplicate of this issue by @gpshead
CharlesBryant-G commentedon Feb 28, 2023
Maybe it's worth taking a step back and looking at the problem in a wider context.
In the PoC, the vulnerability arises not because parse() returns the wrong answer, but because it interprets the url differently from urlopen(). If they were both wrong in the same way it would be harmless. Why is there more than one piece of code which parses URLs? The DRY principle should apply.
Closely related, note that urlparse() does not have a vulnerability at all - any vulnerability is in code which relies on it and does so in a way in which it creates a vulnerability. In the PoC, the vulnerability is in the code for safeURLOpener().
The way in which urlparse() is implemented is fragile and bug prone. As a general principle, parsing code should not look ahead for known delimiters, it should systematically work from the start, advancing over characters tested to be legitimate. So
urlparse('example.com@!$%^&*()_+-={}[]:;"\\|?query#frag')should stop parsing at the '%' as that is not a legal character when not followed by two hex digits. It may return that "example.com@!$" is the path and there are extra characters after the URL (this style of parsing is often convenient when parsing items which may contain things to be parsed), or report failure due to an invalid URL. Instead, an early stage of processing skips ahead to the '?' and '#', so it claims there is a path, query, and fragment. While it could then validate these pieces and realise that the path is invalid, this can be forgotten and makes it unnecessarily difficult and dangerous to make the parser accept a valid URL followed by other characters (because it would need to reliably undo any parsing of anything past the valid part).
[-]Is CVE-2023-24329 still unfixed in 3.11.2?[/-][+]urllib.parse CVE-2023-24329 appears unfixed[/+]gpshead commentedon Mar 1, 2023
We will backport something that makes sense if we determine this is a security issue, that's why I duped the other issue here. Backporting the existing commit further does not make sense to me until the leading space issue, if present as reported here, is resolved. (I haven't taken the time to look. this is not an emergency)
xiaoge1001 commentedon Mar 6, 2023
I tested it and the problem doesn't seem to be fixed. I execute
urlparse(" https://example.com"), the output before and after merging #99421 is the same.xiaoge1001 commentedon Mar 6, 2023
CVE-2023-24329 says that supplying a URL that starts with blank characters is bad.
If a URL-scheme is " https", it will jump out of the loop in the following code:
cpython/Lib/urllib/parse.py
Line 465 in 50b0415
After #99421 is merged, it will exit early:
cpython/Lib/urllib/parse.py
Line 463 in 2e279e8
The code in line 468 is not executed before and after the modification, the subsequent code execution will not change:

when input a URL that starts with blank characters,#99421 doesn't seem to have no effect.
78 remaining items
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
00399: CVE-2023-24329
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
00399: CVE-2023-24329
00399: CVE-2023-24329
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
00399: CVE-2023-24329
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)
Fix failing get_safe_url tests for latest Python 3.8 and 3.9 (#31766)