GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `http.cookiejar` skips domain checks for cookies with a negative `Version` · Issue #160300 · python/cpython

http.cookiejar skips domain checks for cookies with a negative Version #160300

New issue
Copy link
New issue
Copy link
Closed
Closed
http.cookiejar skips domain checks for cookies with a negative Version#160300
Copy link
Assignees
gpshead
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-securityA security issueA security issue

Description

@gpshead
gpshead
opened on Oct 22, 2026
Issue body actions

Bug report

Bug description:

http.cookiejar.DefaultCookiePolicy applies its domain rules only to cookies whose version is 0 (Netscape) or positive (RFC 2965). A Set-Cookie header with a negative Version attribute matches neither case, so the cookie's Domain is never compared with the host that sent it: the cookie is stored for that domain, replaces an existing cookie with the same domain, path and name, and is returned to that domain.

Any server a program contacts with a shared CookieJar controls the header, and can set or overwrite cookies for an unrelated domain (anything with an embedded dot); no cookies are disclosed to it.

import urllib.request
from http.cookiejar import CookieJar
from email.message import Message

class Response:
    def __init__(self, set_cookie):
        self.msg = Message()
        self.msg["Set-Cookie"] = set_cookie
    def info(self):
        return self.msg

for version in "", "; Version=-1":
    jar = CookieJar()
    req = urllib.request.Request("http://www.a.example/")
    jar.extract_cookies(
        Response("k=v; Domain=b.example; Path=/" + version), req)
    req = urllib.request.Request("http://www.b.example/")
    jar.add_cookie_header(req)
    print(repr(version), "->", req.get_header("Cookie"))

Output on main:

'' -> None
'; Version=-1' -> k=v

Expected None in both cases. The code is unchanged since the module was added, so all maintained branches behave the same. This is the set-side counterpart of bpo-35121.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-160300: Reject cookies with a negative version in http.cookiejar #160301
  • [3.15] gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301) #160645
  • [3.14] gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301) #160646
  • [3.13] gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301) #160647
  • [3.12] gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301) #160648
  • [3.11] gh-160300: Reject cookies with a negative version in http.cookiejar (GH-160301) #160649

ANT-2026-TA36I7V7

Activity

  1. gpshead
    self-assigned this
    on Oct 22, 2026
  2. gpshead
    added
    type-securityA security issueA security issue
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Oct 22, 2026
  3. gpshead
    added 4 commits that reference this issue on Oct 25, 2026

    pythongh-160300: Reject cookies with a negative version in http.cooki…

    fea9926

    gh-160300: Reject cookies with a negative version in http.cookiejar (G…

    d59d968

    [3.15] gh-160300: Reject cookies with a negative version in http.cook…

    1b5a6f7

    [3.14] gh-160300: Reject cookies with a negative version in http.cook…

    2473e7a
  4. Yhg1s
    added 2 commits that reference this issue on Oct 25, 2026

    [3.13] gh-160300: Reject cookies with a negative version in http.cook…

    b4198a8

    [3.12] gh-160300: Reject cookies with a negative version in http.cook…

    673da87
  5. pablogsal
    added a commit that references this issue on Oct 25, 2026

    [3.11] gh-160300: Reject cookies with a negative version in http.cook…

    6229895
  6. gpshead commented on Oct 25, 2026

    @gpshead
    gpshead
    on Oct 25, 2026
    MemberAuthor
    More actions

    thanks for the reviews!

  7. gpshead
    closed this as completedon Oct 25, 2026
  8. icanhasmath
    added 2 commits that reference this issue on Oct 28, 2026

    [3.11] pythongh-160300: Reject cookies with a negative version in htt…

    ed638dc

    [3.11] pythongh-160300: Reject cookies with a negative version in htt…

    ac2bf3d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gpshead
    gpshead

Labels

stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-securityA security issueA security issue

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.