Skip to content

Refresh expiration dates for empty-valued cookies during replay - #8520

Merged
mhils merged 5 commits into
mitmproxy:mainfrom
hakarrr:fix/refresh-empty-cookie-expiration
Oct 25, 2026
Merged

mhils merged 5 commits into
mitmproxy:mainfrom
hakarrr:fix/refresh-empty-cookie-expiration

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Description

refresh_set_cookie_header() rejects any falsey cookie value. An empty string is valid, however: RFC 6265 section 4.1.1 defines cookie-value as zero or more cookie octets, optionally quoted.

For example, session=; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Path=/ raises ValueError instead of shifting its expiration. Response.refresh() catches that error and silently retains the stale header, so replayed empty-valued cookies do not receive the same date adjustment as nonempty cookies.

Reject a missing value (None) rather than an empty string. This keeps genuinely valueless cookie rejection and the existing handling of malformed expiration dates unchanged.

Tests exercise both session= and session="" through the cookie helper and a real Response.refresh(), plus a valueless-cookie control. Four new cases fail on unchanged base 9125647; all five pass with the fix. This is separate from #8415's Max-Age precedence changes and does not change expiration precedence or parsing.

Validation in a separate current-base tree, without the XML changes from #8518:

  • 120 cookie and HTTP tests pass.
  • Broad Python run: 2008 passed, 2 skipped, one failure creating a TUN device in this environment. The same TUN test fails against unchanged base too.
  • Repository-wide Ruff checks pass.
  • Mypy: no issues in 288 source files.

No live-browser replay or Windows/macOS test was run.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

@mhils mhils left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mhils
mhils merged commit 6debf65 into mitmproxy:main Oct 25, 2026
28 checks passed
lups2000 pushed a commit to lups2000/mitmproxy that referenced this pull request Oct 31, 2026
…proxy#8520)

* Fix cookie validation check for None values

Co-authored-by: generaltony007 <[email protected]>

* test(http): cover refreshing empty and valueless cookies

Co-authored-by: generaltony007 <[email protected]>

* test(http): refresh empty cookie expiration through responses

Co-authored-by: generaltony007 <[email protected]>

* docs: note empty cookie expiration refresh fix

Co-authored-by: generaltony007 <[email protected]>

* [autofix.ci] apply automated fixes

---------

Co-authored-by: generaltony007 <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
zchee added a commit to zchee/mitmproxy-go that referenced this pull request Nov 3, 2026
Only consume an Expires comma after a weekday. Keep present empty
cookie values valid for replay while rejecting missing names or values.
Match mitmproxy/mitmproxy#8489 and mitmproxy/mitmproxy#8520.

Co-Authored-By: Codex <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JzMvb3jz3dRT93GMjXUfQQ
@hakarrr
hakarrr deleted the fix/refresh-empty-cookie-expiration branch November 25, 2026 06:23
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.

2 participants