Repository navigation
Fix handling of duplicate cookie names in RequestCookies - #505
Open
DresdenGman wants to merge 1 commit into
Open
DresdenGman wants to merge 1 commit into
DresdenGman wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #182.
RequestCookiesmishandled duplicate cookie names in both directions:_mutate_headerstopped at the first match, leaving any further segments with the same name untouched in the header. That includes the case reported in the cookie header with multiple cookies and the same key is handled incorrectly #182 comments: after redacting cookies key by key, a second segment with the same name still held its plaintext value.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:
_mutate_headerrebuilds 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.