Title: `SimpleCookie` regex can make parsing extremely slow for adversarial payloads · Issue #149028 · python/cpython · GitHub
Open Graph Title: `SimpleCookie` regex can make parsing extremely slow for adversarial payloads · Issue #149028 · python/cpython
X Title: `SimpleCookie` regex can make parsing extremely slow for adversarial payloads · Issue #149028 · python/cpython
Description: Bug report Bug description: The current version of http.cookies has a potential performance/security regression (seemingly introduced by #113663) and detected through fuzzing, where a bad cookie payload could significantly slow down requ...
Open Graph Description: Bug report Bug description: The current version of http.cookies has a potential performance/security regression (seemingly introduced by #113663) and detected through fuzzing, where a bad cookie pa...
X Description: Bug report Bug description: The current version of http.cookies has a potential performance/security regression (seemingly introduced by #113663) and detected through fuzzing, where a bad cookie pa...
Opengraph URL: https://github.com/python/cpython/issues/149028
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`SimpleCookie` regex can make parsing extremely slow for adversarial payloads","articleBody":"# Bug report\n\n### Bug description:\n\nThe current version of `http.cookies` has a potential performance/security regression (seemingly introduced by #113663) and detected through fuzzing, where a bad cookie payload could significantly slow down request processing on a server relying on `SimpleCookie` (such as `bottle` [here](https://github.com/bottlepy/bottle/blob/2a743a3/bottle.py#L1175) or `tornado` [there](https://github.com/tornadoweb/tornado/blob/3251ead/tornado/httputil.py#L551)). Such a cookie could be easily be crafted by a bad actor, leading to potential denial of service. \n\n[This branch](https://github.com/python/cpython/compare/main...KowalskiThomas:cpython:kowalski/fix-avoid-slow-regex-in-cookie-parsing) on my fork proposes ~an alternative regular expression that does not seem to have the problem~ (removed this to make it clear that my intention was _not_ to get that merged 😅) as well as a reproducer. When run (without the regex change), it clearly shows the problem:\n\n```\n$ ./python reproducer_cookie_redos.py\nTiming SimpleCookie().load() with increasing payload size\n units bytes time\n 1 18 0.0001s\n 2 36 0.0001s\n 3 54 0.0003s\n 4 72 0.0010s\n 5 90 0.0042s\n 6 108 0.0163s\n 7 126 0.0648s\n 8 144 0.2560s\n 9 162 1.0294s\n 10 180 4.1919s\n 11 198 16.6055s\n```\n\nFor reference, the reproducer is \n\n```py\nimport sys\nimport time\nimport http.cookies\n\n_UNIT = 'x=\"qu\\\\\"qu\\\\\\\\\"quot\u003c' # raw: x=\"qu\\\"qu\\\\\"quot\u003c\n\ndef make_payload(units: int = 11) -> str:\n \"\"\"Return a Cookie header value that causes ~4^units backtrack steps.\"\"\"\n return (\" \" + _UNIT) * units\n\nprint(\"Timing SimpleCookie.load with increasing payload size\")\nprint(f\" {'units':>5} {'bytes':>6} {'time':>10}\")\nfor n in range(1, 14):\n payload = make_payload(n)\n start = time.perf_counter()\n http.cookies.SimpleCookie().load(payload)\n elapsed = time.perf_counter() - start\n print(f\" {n:>5} {len(payload):>6} {elapsed:>10.4f}s\")\n if elapsed > 10:\n print(\" (stopping)\")\n break\n```\n\n**Note** I did not report this as a security issue because the original PR went out in August 2025; 3.14 was already in beta and so only the unreleased version of Python is affected. I downloaded and built 3.14 manually to make sure, and 3.14 is _not_ affected by this regression.\n\n> The PSRT does not accept reports that only affect pre-release versions of software, as these features are considered \"in-development\", please open public issues. ([source](https://www.python.org/dev/security/))\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-149145\n* gh-149182\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/KowalskiThomas","@type":"Person","name":"KowalskiThomas"},"datePublished":"2026-04-26T20:16:57Z","url":"https://github.com/python/cpython/issues/149028"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8be103b4-948f-558e-eddf-3c310143f8eb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D246:38E318:32D9B88:4063F0F:6B020950 |
| html-safe-nonce | 768bdaf709757bc3516fab2bb0c459fce1affc5dfde023a5b9b34d9028e10f4f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjQ2OjM4RTMxODozMkQ5Qjg4OjQwNjNGMEY6NkIwMjA5NTAiLCJ2aXNpdG9yX2lkIjoiODY1MDQxODM4OTEzNjgzNjk0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 85993d2efe816d93b5e8a24e8af1e4960638fbebf69de96a16d33dff460141ed |
| hovercard-subject-tag | issue:4331878791 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149028/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0c4d8da5e4a5e838f0dbaee351e51b69dedd6d9e9f27ea6b4f4346b2b7fe2490/python/cpython/issues/149028 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0c4d8da5e4a5e838f0dbaee351e51b69dedd6d9e9f27ea6b4f4346b2b7fe2490/python/cpython/issues/149028 |
| og:image:alt | Bug report Bug description: The current version of http.cookies has a potential performance/security regression (seemingly introduced by #113663) and detected through fuzzing, where a bad cookie pa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KowalskiThomas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width