Restrict pickle deserialization to safe types (CVE-2025-69872)#364
Open
a2811057970 wants to merge 1 commit into
Open
Restrict pickle deserialization to safe types (CVE-2025-69872)#364a2811057970 wants to merge 1 commit into
a2811057970 wants to merge 1 commit into
Conversation
BREAKING CHANGE: Pickle deserialization now only permits safe built-in types (builtins, collections, datetime, decimal, fractions, uuid). Arbitrary objects can no longer be deserialized from cache, preventing code execution via crafted pickle payloads. Users caching custom types should migrate to JSONDisk or a custom Disk subclass. There is no opt-out mechanism by design. - Add SafeUnpickler with allowlist-based find_class override - Add UnpicklingError (inherits pickle.UnpicklingError) for downstream compatibility with libraries catching pickle.PickleError - Support pickle protocols 0-5 via __builtin__, copy_reg, and _codecs allowlist entries - Use frozenset values in SAFE_PICKLE_CLASSES to prevent runtime bypass - Bump version to 6.0.0 (breaking change per semver) This takes a different approach to PR grantjenks#361 (HMAC envelope). The HMAC approach still allows arbitrary deserialization once the signature is verified, meaning an attacker with read+write access to the cache directory can read the auto-generated key file and forge valid payloads. The allowlist approach blocks dangerous types regardless of filesystem access. Fixes: CVE-2025-69872 Closes: grantjenks#357, grantjenks#360, grantjenks#362
Author
|
@grantjenks would appreciate a review when you get a chance. This is a minimal alternative to #361 for CVE-2025-69872 — 150 lines of additive code vs 1000+ lines, with stronger security guarantees (blocks dangerous types even if the attacker has full cache directory access). |
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.
Summary
Mitigates CVE-2025-69872 by restricting pickle deserialization to a hardcoded allowlist of safe built-in types. Arbitrary objects can no longer be deserialized from cache, preventing code execution via crafted pickle payloads.
Approach
This uses a
SafeUnpicklerwith an allowlist-basedfind_classoverride — a fundamentally different approach to #361 (HMAC envelope). The key difference:What's allowed
int,float,str,bytes,bytearray,list,dict,tuple,set,frozenset,complex,range,slice,object,bool,None,collections.OrderedDict,collections.defaultdict,collections.deque,datetime.*,decimal.Decimal,fractions.Fraction,uuid.UUIDEverything else raises
UnpicklingErroron read.Breaking change
This is intentionally a breaking change (version bumped to 6.0.0). Users caching custom types have two migration paths:
JSONDiskfor JSON-serializable dataDiskand overrideget()/fetch()with a custom serializerThere is no opt-out by design — an escape hatch would just be cargo-culted by every downstream that hits an error.
Downstream compatibility
UnpicklingErrorinherits frompickle.UnpicklingErrorso libraries that catchpickle.PickleError(e.g. dvc-data'stranslate_pickle_errordecorator) handle it gracefully.Tests
isortandbluepassFixes CVE-2025-69872
Closes #357, #360, #362