[PR #12091/8a631e74 backport][3.14] Restrict pickle deserialization in CookieJar.load()#12105
Merged
Dreamsorcerer merged 9 commits into3.14from Feb 22, 2026
Conversation
--------- Co-authored-by: Sam Bull <[email protected]> (cherry picked from commit 8a631e7)
5 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.14 #12105 +/- ##
========================================
Coverage 98.24% 98.25%
========================================
Files 129 129
Lines 45236 45604 +368
Branches 2450 2470 +20
========================================
+ Hits 44442 44808 +366
- Misses 612 615 +3
+ Partials 182 181 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
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.
This is a backport of PR #12091 as merged into master (8a631e7).
Changes
_RestrictedCookieUnpickler— Apickle.Unpicklersubclass that only allows cookie-related types (SimpleCookie,Morsel,defaultdict, and safe builtins). All other types (e.g.os.system,eval,exec,subprocess) raiseUnpicklingError.CookieJar.load()— Now uses_RestrictedCookieUnpicklerinstead of barepickle.load(). Fully backward compatible with existing pickle files containing legitimate cookies.CookieJar.save_json()/load_json()— New safe JSON-based alternatives for cookie persistence, immune to deserialization attacks by design.Documentation — Added
.. warning::directives tosave()/load()and documented the newsave_json()/load_json()methods.Tests — Added tests verifying:
os.system,eval,subprocess.callpayloads are blockedTest plan
os.system,eval,exec,subprocess.call,os.popen) are all rejected withUnpicklingErrortest_pickle_formatregression test data loads through restricted unpicklersave_json/load_jsonroundtrip preserves all cookie attributes (domain, path, secure, httponly, expires, max-age, samesite, partitioned)🤖 Generated with Claude Code