Summary
A flaw in picklescan prior to version 0.0.28 allows malicious pickle payloads using torch.fx.experimental.symbolic_shapes.ShapeEnv.evaluate_guards_expression to bypass detection.
Attackers can embed code that executes when the pickle is loaded, exposing applications that rely on picklescan for pre-load safety checks to remote code execution risks.
Affected context
This vulnerability affects environments that:
- Use Python pickle files for model, configuration, or data exchange
- Rely on picklescan (pre-0.0.28) to statically vet pickle payloads before loading
- Work with PyTorch and the torch.fx.experimental.symbolic_shapes APIs
The risk materializes when untrusted or semi-trusted pickle files are accepted and assumed safe solely based on picklescan scanning results.
Exploit preconditions
- Attack surface: Any application, service, or notebook that loads pickle files after scanning them with vulnerable versions of picklescan.
- Required access: Ability to supply or modify pickle files consumed by a victim (e.g., uploaded models, shared artifacts, or datasets).
- Trigger point: A victim process deserializes a crafted pickle using Python's pickle mechanisms, trusting picklescan's prior analysis.
- Why exploitation is possible: picklescan before 0.0.28 does not recognize or flag dangerous calls to torch.fx.experimental.symbolic_shapes.ShapeEnv.evaluate_guards_expression, allowing attacker-controlled code paths to remain undetected in the serialized stream.
Why this happens
The underlying bug is an incomplete threat model and coverage gap in a security scanning tool for pickle files.
In terms of CWE-502: Unsafe Deserialization, the pickle format can encode executable behavior via object graphs and callable references.
picklescan's detection logic failed to treat torch.fx.experimental.symbolic_shapes.ShapeEnv.evaluate_guards_expression as a potentially dangerous execution sink, leaving a deserialization pathway where attacker-controlled data can drive function execution without being flagged.
Abstractly, this reflects a pattern where deserialization safety tools do not exhaustively enumerate or model all dangerous constructors, methods, or evaluation points available in the runtime environment.
Potential impact
- Remote code execution in the context of the process loading the malicious pickle
- Compromise of ML pipelines, including tampering with models and training data
- Unauthorized access to sensitive data available to the deserializing application
- Abuse of victim infrastructure for further attacks, lateral movement, or cryptomining
- Corruption of analytical results and model behavior due to poisoned artifacts
General mitigation guidance
Effective mitigation focuses on reducing trust in pickle inputs and limiting what deserialization can do:
- Treat all pickle files as untrusted unless they come from tightly controlled, authenticated sources.
- Prefer non-executable serialization formats (e.g., JSON, protocol buffers) for data exchange where possible.
- Implement allowlist-based loading patterns that restrict which modules, classes, and functions can be referenced during deserialization.
- Run deserialization operations with least privilege, in isolated environments or sandboxes, so that unexpected execution is contained.
- Regularly review and update safety tools and policies that analyze serialization streams to reflect new dangerous APIs and execution sinks.
How teams detect issues like this
Detection typically combines tool-based checks with process controls:
- Use static analysis or security review tools that understand Python pickle internals and can flag references to risky functions and modules (including PyTorch's symbolic shape evaluation).
- Incorporate code review practices that question any use of pickle for untrusted input and highlight reliance on single tools for safety validation.
- Establish policies that restrict deserialization of artifacts from external or user-controlled sources without additional validation or sandboxing.
- Monitor runtime environments for unusual child processes, file access patterns, or network activity triggered during or immediately after deserialization operations.

