http.cookies.BaseCookie.load() applies partial state before raising CookieError
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug description
BaseCookie.load() parses the cookie string in two phases: parse then apply. The comment says it rejects the string if syntactically invalid. However, _is_legal_key() validation runs during the apply phase (inside Morsel.set()), not the parse phase. Cookies before an illegal key are applied to the jar before CookieError is raised.
from http.cookies import SimpleCookie, CookieError
C = SimpleCookie()
try:
C.load("a=1; b,c=2; d=3")
except CookieError:
pass
print(len(C)) # 1, expected 0
Related to gh-84183 but distinct: that issue is about raise-vs-silent for different invalid inputs; this is about partial state when CookieError IS raised.
CPython versions tested on
3.13, 3.14, main
Operating systems tested on
macOS
Linked PRs
- gh-154674
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 at http.cookies.BaseCookie.load() and reproduce the issue with the cookie string shown in the report. Verify that a CookieError leaves the cookie jar empty; the issue body links PR gh-154674, so check that work before proceeding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100