Skip to content

Fix handling of duplicate cookie names in RequestCookies - #505

Open
DresdenGman wants to merge 1 commit into
Pylons:mainfrom
DresdenGman:fix-182-duplicate-cookies
Open

DresdenGman wants to merge 1 commit into
Pylons:mainfrom
DresdenGman:fix-182-duplicate-cookies

Conversation

@DresdenGman

Copy link
Copy Markdown

Fixes #182.

RequestCookies mishandled duplicate cookie names in both directions:

This change keeps the existing dict-style API — it does not attempt the MultiDict redesign that #182 left undecided — and makes the two paths consistent:

  • The cache now keeps the first value for a duplicated name.
  • _mutate_header rebuilds the header around the first match and drops the remaining segments with the same name (which also removes a stray ; the old code left behind when deleting the first segment).

One deliberate behavior change to flag: reading a duplicated cookie name now returns the first value instead of the last. That is the behavior #182 asks for, but it is a visible change and worth an explicit maintainer call.

Tests: full suite 2403 passed against a baseline of 2398 (1 xfailed on both sides), no new failures. The 5 new tests cover first-value reads, replacement and deletion across duplicate segments, and the redaction scenario from the issue comments.

The first value of a repeated cookie name now wins when reading, as
user agents order cookies with the highest priority first. Setting or
deleting a cookie now replaces/removes every occurrence in the header,
so stale duplicate values can no longer survive (e.g. when sanitizing
a request for logging).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cookie header with multiple cookies and the same key is handled incorrectly

1 participant