python / python/cpython

http.cookies.BaseCookie.load() applies partial state before raising CookieError

Open
#154,546 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.