Summary
A validation gap in Picklescan before 0.0.33 fails to detect the numpy.f2py.crackfortran._eval_length gadget embedded in pickle __reduce__ methods, leaving a known code execution vector unblocked.
Attackers can craft malicious pickle files that pass Picklescan's checks yet execute arbitrary Python code when loaded by applications that rely on Picklescan for safety validation.
Affected context
This vulnerability affects Python applications and services that:
- Use Picklescan (before 0.0.33) to validate or "sanitize" pickle files, and
- Continue to load pickles after Picklescan indicates they are safe, and
- Have
numpyavailable in the runtime environment.
In these contexts, the scanner's inability to recognize a specific dangerous gadget chain allows malicious payloads to be treated as benign.
Exploit preconditions
- Attack surface: Any pickle-loading functionality that relies on Picklescan as a security gate.
- Required access: Ability to supply or influence pickle data consumed by the target application (e.g., file upload, API input, shared storage).
- Trigger point: Deserialization of an attacker-crafted pickle object that uses
numpy.f2py.crackfortran._eval_lengthwithin__reduce__. - Why exploitation is possible: Picklescan's detection ruleset does not cover this gadget, so the malicious pickle can bypass validation and be deserialized by the victim's code as if it were safe.
Why this happens
The underlying issue is incomplete coverage of dangerous deserialization gadgets within a security validation tool.
Although Picklescan attempts to detect risky constructs in pickle __reduce__ methods, its rules do not include the numpy.f2py.crackfortran._eval_length gadget, a callable that can be abused to execute arbitrary code when reconstructed during unpickling.
This aligns with CWE-502: Unsafe Deserialization, where untrusted serialized data is processed in a way that can instantiate objects or call code with attacker-controlled parameters, and the protective mechanism (Picklescan) fails to fully enforce safe patterns.
Potential impact
- Execution of arbitrary Python code in the context of the deserializing process
- Compromise of application servers or worker processes loading attacker-controlled pickles
- Access to sensitive data handled by the affected application
- Use of the compromised environment for lateral movement or further attacks
General mitigation guidance
Mitigation focuses on reducing trust in serialized input and hardening deserialization boundaries rather than relying solely on gadget blacklists.
Recommended defensive patterns include:
- Avoiding
picklefor untrusted or semi-trusted data; prefer safer serialization formats (e.g., JSON, msgpack with strict schemas) where possible. - Treating any pickle from external or user-influenced sources as untrusted, even if a scanner reports it "safe".
- Isolating deserialization in constrained environments (e.g., separate processes, containers, or sandboxes) with minimal privileges and restricted filesystem/network access.
- Applying least-privilege execution for services that must use pickle, limiting what damage arbitrary code execution can cause.
- Using allowlist-based object reconstruction patterns (e.g., custom unpicklers that only permit specific classes and modules) to constrain gadget surfaces.
How teams detect issues like this
Detection strategies should aim to identify both unsafe deserialization practices and overreliance on validation tools:
- Static analysis rules to flag use of
pickle.load,pickle.loads, and equivalent APIs when applied to data that can be influenced by external sources. - Code review checklists that highlight any security decisions based solely on Picklescan (or similar tools) and require justification or additional controls.
- Scanning dependency code and configuration for deserialization logic that runs post-validation, ensuring no unguarded reintroduction of risky gadgets.
- Runtime monitoring and logging around deserialization paths, including anomaly detection for unexpected module imports or subprocess/system calls triggered shortly after unpickling.
Automated review tools can help surface dangerous deserialization patterns and enforce policies forbidding untrusted pickle usage.

