Skip to content

http.cookies: SimpleCookie silently drops cookies containing standard 'Partitioned' attribute #162126

Open

Description

@klnmurthi12345

Bug report

When parsing cookie headers with the modern Partitioned attribute (CHIPS / RFC 6265bis, supported across all major web browsers and modern web frameworks), http.cookies.SimpleCookie silently discards the entire cookie. In addition, attempting to set morsel['partitioned'] = True raises CookieError: Invalid attribute 'partitioned'.

Reproduction:

from http import cookies

# 1. Loading a cookie with the Partitioned flag
c1 = cookies.SimpleCookie()
c1.load('session=12345; Secure; SameSite=None; Partitioned')
print('Cookies loaded (with Partitioned):', len(c1))
# Output: Cookies loaded (with Partitioned): 0  (silently dropped!)

# 2. Same cookie without Partitioned
c2 = cookies.SimpleCookie()
c2.load('session=12345; Secure; SameSite=None')
print('Cookies loaded (without Partitioned):', len(c2))
# Output: Cookies loaded (without Partitioned): 1

# 3. Attempting to set Partitioned attribute programmatically
c3 = cookies.SimpleCookie()
c3['session'] = '12345'
try:
    c3['session']['partitioned'] = True
except cookies.CookieError as e:
    print('Error setting partitioned:', e)
    # Output: Error setting partitioned: Invalid attribute 'partitioned'

Actual Behavior:

Because 'partitioned' is not present in Morsel._reserved and Morsel._flags, when _BaseCookie.__parse_string encounters Partitioned, it hits the valueless-token fallback:

            elif value is not None:
                parsed_items.append((TYPE_KEYVALUE, key, self.value_decode(value)))
                morsel_seen = True
            else:
                # Invalid cookie string
                return

This triggers the early return and causes SimpleCookie to discard the entire cookie header without loading any morsels.

Expected Behavior:

Partitioned should be recognized as a valid boolean flag attribute (like Secure and HttpOnly), allowing modern partitioned cookies to be parsed without dropping the cookie, and serialized as ; Partitioned.

Root Cause:

In Lib/http/cookies.py:

  • Morsel._reserved lacks 'partitioned': 'Partitioned'.
  • Morsel._flags lacks 'partitioned'.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions