http.cookiejar.http2time raises ValueError instead of returning None for a strict-format fake month
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug description
http.cookiejar.http2time() documents that it returns None for an
unrecognized date format, but its STRICT_DATE_RE fast path raises a raw
ValueError when the month field matches the pattern [JFMASOND][a-z][a-z]
yet names a month that does not exist:
>>> from http.cookiejar import http2time
>>> http2time('Wed, 09 Foo 1994 22:23:32 GMT')
Traceback (most recent call last):
...
ValueError: 'foo' is not in list
>>> http2time('Wed, 09 Feb 1994 22:23:32 GMT') # a real month still works
760832612.0
The slower parser (_str2time) already handles the same input via
try/except and returns None; only the strict fast path leaks. It is
reachable from parse_ns_headers() through a cookie's expires= attribute,
e.g. Set-Cookie: x=y; expires=Wed, 09 Foo 1994 22:23:32 GMT.
gh-60385 previously established the "returns None, never raises" contract
for a different http2time code path; the later STRICT_DATE_RE fast path
reintroduced a leak on this separate path.
CPython versions tested on
3.13, 3.14, 3.15
Operating systems tested on
Linux, macOS
Linked PRs
- gh-153678
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Python's http.cookiejar module by tracing http2time() through the STRICT_DATE_RE fast path and comparing it with _str2time's handling of invalid months. The change is done when a strict-format fake month returns None without raising, while a valid month still parses successfully; consider the parse_ns_headers() cookie expiry path described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100