8000 bpo-43075: Fix ReDoS in request by yetingli · Pull Request #24391 · python/cpython · GitHub
[go: up one dir, main page]

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

bpo-43075: Fix ReDoS in request #24391

merged 7 commits into from
Apr 7, 2021

Conversation

yetingli
Copy link
Contributor
@yetingli yetingli commented Jan 31, 2021

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@yetingli

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

We also demand... A SHRUBBERY!

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

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

@yetingli yetingli changed the title Fix ReDoS in request bpo-43075: Fix ReDoS in request Jan 31, 2021
@orsenthil
Copy link
Member

Hi @yetingli - I am not sure, but do you think if it makes sense to demonstrate (better /linear) performance with request parsing of the Header in the urllib testcase with this change? Something that was demonstrated in https://bugs.python.org/file49778/redos_python.py - Not necessarily using pyperf.

As I said, I am not sure what that kind of test will be.

@serhiy-storchaka
Copy link
Member

I concur with @orsenthil. Just add a code which 8000 takes less than a second with a fix, and more than a hour without it. It should be enough to notice regression if we break that code. Say a million of commas.

@@ -0,0 +1 @@
Fix ReDoS in request
Copy link
Member

Choose a reason for hiding this comment

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

Please be more informative. If you are Python user reading changelog, what it would say to you? What request? What type of ReDoS? Does it affect your code if it does so and so, or you can ignore it?

@github-actions
Copy link
github-actions bot commented Mar 3, 2021

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

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Mar 3, 2021
@rotuna
8000 Copy link
Contributor
rotuna commented Mar 3, 2021

Hi, I saw the mail in Core Mentorship.

I'd love to work on this! Thanks @orsenthil

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Mar 4, 2021
@github-actions
Copy link
github-actions bot commented Apr 4, 2021

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

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Apr 4, 2021
Copy link
Member
@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Can you please update the NEWS entry, as @serhiy-storchaka requested?

For the regex, we can use your fix. It's good enough. But I'm curious if we cannot be stricter about it.

@@ -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?

@yetingli
Copy link
Contributor Author
yetingli commented Apr 7, 2021

Can you please update the NEWS entry, as @serhiy-storchaka requested?

For the regex, we can use your fix. It's good enough. But I'm curious if we cannot be stricter about it.

Thank you for your reminder. Sorry, I was not familiar with the specification of PR submission before, and now I have updated the NEWS entry.

@@ -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 server and needs remote attackers to control the HTTP server.
Copy link
Member

Choose a reason for hiding this comment

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

"This ReDoS issue is on the client server"

Do you mean "client side"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's the “client side”. I wrote it based on your reviews:joy:, and I'll change it right away.

Please explain that the issue is on the client server, the attacker needs to control the HTTP server.

@vstinner vstinner merged commit 7215d1a into python:master Apr 7, 2021
@miss-islington
Copy link
Contributor

Thanks @yetingli for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Contributor

Thanks @yetingli for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Apr 7, 2021
@bedevere-bot
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 7, 2021
Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
@bedevere-bot
Copy link

GH-25248 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 7, 2021
Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
@miss-islington
Copy link
Contributor

Thanks @yetingli for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @yetingli for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@bedevere-bot
Copy link

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

@bedevere-bot
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 7, 2021
Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 7, 2021
Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
miss-islington added a commit that referenced this pull request Apr 7, 2021
Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
vstinner pushed a commit that referenced this pull request Apr 7, 2021
…H-25247)

Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
gentoo-bot pushed a commit to gentoo/cpython that referenced this pull request May 2, 2021
Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
(backported to Python 2.7 by Michał Górny)
ambv pushed a commit that referenced this pull request May 4, 2021
…25249)

Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
ned-deily pushed a commit that referenced this pull request May 6, 2021
…H-25250)

Fix Regular Expression Denial of Service (ReDoS) vulnerability in
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.
(cherry picked from commit 7215d1a)

Co-authored-by: Yeting Li <liyt@ios.ac.cn>
@StayPirate
Copy link

CVE-2021-3733 has now been assigned to this security bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants
0