Skip to content

[PR #13930/b1f6c87b backport][3.14] Add limits for client cookie handling - #13942

Merged
bdraco merged 1 commit into
3.14from
patchback/backports/3.14/b1f6c87b2bd3bd80f2b6c22ff46e11d00921e412/pr-13930
Oct 4, 2026
Merged

bdraco merged 1 commit into
3.14from
patchback/backports/3.14/b1f6c87b2bd3bd80f2b6c22ff46e11d00921e412/pr-13930

Conversation

@bdraco

@bdraco bdraco commented Oct 4, 2026

Copy link
Copy Markdown
Member

This is a backport of PR #13930 as merged into master (b1f6c87).

What do these changes do?

Add limits to client cookie handling. Each Set-Cookie field now produces exactly one cookie, as browsers do, and CookieJar caps how many cookies it stores and how large a Cookie header it builds. Eviction follows Firefox, so expired and non secure cookies go first, least recently used first.

Are there changes in behavior for the user?

The jar applies these limits:

  • 50 Set-Cookie fields per response, 32 attributes per field;
  • 4,096 octets for a cookie's name and value, 1,024 octets per attribute value;
  • 180 cookies per domain and 3,300 in total;
  • 150 cookies and 8,190 octets per Cookie request header.

Extra name=value pairs after the first one in a Set-Cookie field are now ignored instead of becoming separate cookies; see the breaking fragment. Cookies passed with cookies= and an explicit Cookie header are not limited.

Is it a substantial burden for the maintainers to support this?

No, the limits are private constants and there is no new public API.

Related issue number

N/A

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

Local test run
pytest (full suite, xdist): 5833 passed, 25 skipped, 17 xfailed
cookie and client tests, C extensions: 863 passed, 4 skipped, 1 xfailed
cookie and client tests, AIOHTTP_NO_EXTENSIONS=1: 863 passed, 4 skipped, 1 xfailed

Drafted with Claude Opus 5.5; reviewed by @bdraco.

Co-authored-by: iamibi <[email protected]>
(cherry picked from commit b1f6c87)
@agentscanapp

agentscanapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.46%. Comparing base (f1750ba) to head (da9ea9b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             3.14   #13942      +/-   ##
==========================================
+ Coverage   96.38%   96.46%   +0.07%     
==========================================
  Files         161      161              
  Lines       53348    54268     +920     
  Branches     2888     2957      +69     
==========================================
+ Hits        51421    52351     +930     
+ Misses       1750     1743       -7     
+ Partials      177      174       -3     
Flag Coverage Δ
Autobahn 21.22% <14.66%> (-0.11%) ⬇️
CI-GHA 96.30% <100.00%> (+0.07%) ⬆️
OS-Linux 96.10% <100.00%> (+0.08%) ⬆️
OS-Windows 94.21% <100.00%> (+0.11%) ⬆️
OS-macOS 95.63% <100.00%> (+0.08%) ⬆️
Py-3.10 95.58% <100.00%> (+0.09%) ⬆️
Py-3.11 95.82% <100.00%> (+0.08%) ⬆️
Py-3.12 95.89% <100.00%> (+0.08%) ⬆️
Py-3.13 95.89% <100.00%> (+0.08%) ⬆️
Py-3.14 95.91% <99.81%> (+0.08%) ⬆️
Py-3.14t 95.30% <99.81%> (+0.09%) ⬆️
Py-pypy-3.12 94.14% <100.00%> (+0.11%) ⬆️
VM-macos 95.63% <100.00%> (+0.08%) ⬆️
VM-ubuntu 96.10% <100.00%> (+0.08%) ⬆️
VM-windows 94.21% <100.00%> (+0.11%) ⬆️
cython-coverage 79.82% <69.57%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed

codspeed Bot commented Oct 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 86 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing patchback/backports/3.14/b1f6c87b2bd3bd80f2b6c22ff46e11d00921e412/pr-13930 (da9ea9b) with 3.14 (f1750ba)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Adds cookie parsing and storage limits to the HTTP client.

The confirmed compatibility regression is non-blocking; this review does not find a reason to prevent merging.

Reviews (1) · Last reviewed commit: "Add limits for client cookie handling (#..."

Comment thread aiohttp/_cookie_helpers.py Resolved
@bdraco
bdraco merged commit 6963ee0 into 3.14 Oct 4, 2026
50 checks passed
@bdraco
bdraco deleted the patchback/backports/3.14/b1f6c87b2bd3bd80f2b6c22ff46e11d00921e412/pr-13930 branch October 4, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant