Skip to content

bpo-43075: Fix ReDoS in request #24391

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 7 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ class AbstractBasicAuthHandler:
# (single quotes are a violation of the RFC, but appear in the wild)
rx = re.compile('(?:^|,)' # start of the string or ','
'[ \t]*' # optional whitespaces
'([^ \t]+)' # scheme like "Basic"
'([^ \t,]+)' # scheme like "Basic"
Copy link
Member

Choose a reason for hiding this comment

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

This fix is correct, but can't we be more strict to parse the scheme? Do we really want to accept non-ASCII characters in the scheme? Or Unicode spaces? HTTP is like very conservative and I expect the scheme to be only made of ASCII letters maybe with "_" and "-" characters. Is there a RFC giving the grammar for the HTTP Basic scheme?

'[ \t]+' # mandatory whitespaces
# realm=xxx
# realm='xxx'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Regular Expression Denial of Service (ReDoS) vulnerability in :class:`urllib.request.AbstractBasicAuthHandler`. The ReDoS-vulnerable regex has quadratic worst-case complexity and it allows cause a denial of service when identifying crafted invalid RFCs. This ReDoS issue is on the client side and needs remote attackers to control the HTTP server.