The pickle module for Python object serialization. pickle.load() and pickle.loads() execute arbitrary code during deserialization via __reduce__ — always unsafe with untrusted input. Use json or signed payloads instead.
.load().loads().Unpickler()from codepathfinder.python_decorators import python_rule
from codepathfinder import calls, flows
from codepathfinder.presets import PropagationPresets
@python_rule(
id="PYTHON-DESER-001",
name="Unsafe Pickle Deserialization",
severity="CRITICAL",
category="deserialization",
cwe="CWE-502",
owasp="A08:2021",
message="Untrusted data flows to pickle.loads(). Use json.loads() or signed payloads.",
)
def detect_pickle_deserialization():
return flows(
from_sources=[
calls("request.data"),
calls("request.get_data"),
calls("*.read"),
calls("*.recv"),
],
to_sinks=[calls("pickle.loads"), calls("pickle.load")],
sanitized_by=[calls("hmac.compare_digest"), calls("*.verify_signature")],
propagates_through=PropagationPresets.standard(),
scope="local",
)
pathfinder scan --ruleset custom/security --project ..load()Sinkpickle.load(file: IO) -> Any
Reads a pickled object from a file. Arbitrary-code-execution sink on untrusted data.
0.loads()Sinkpickle.loads(data: bytes) -> Any
Deserializes a pickle byte string. RCE sink on untrusted data.
0.Unpickler()Sinkpickle.Unpickler(file: IO) -> Unpickler
Stateful unpickler. The load() method is the sink.
0| FQN | Field | |
|---|---|---|
| pickle | fqns[0] |
Wrong FQN → 0 findings. Verify with: change fqns to garbage → must produce 0 results.
from codepathfinder.go_rule import PyPickle