Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› Pickle
Cyber Security

Pickle

← Back to Glossary
By NHI Mgmt Group Updated October 12, 2026 Domain: Cyber Security

Pickle is a Python serialisation format that stores and recreates complex objects, including behaviour as well as data. Its convenience is also its weakness, because unpickling can invoke object hooks and callable paths that become dangerous when the source is attacker-controlled.

What Pickle Is and Why It Matters

Pickle is a Python serialisation format that can preserve complex object graphs, not just plain data. That convenience is also its main danger: deserialisation may execute hooks or callables embedded in the object stream.

For that reason, pickle is best understood as a programmatic object transport mechanism, not a safe interchange format. Its design assumes the input is trusted, and that assumption changes how it should be used in production systems.

How Pickle Works

Pickle turns Python objects into a byte stream and can later rebuild them into live objects. During reconstruction, Python may invoke special methods such as __reduce__ or other object-specific logic, which is what makes pickle powerful and also dangerous.

This behaviour means pickle is tightly bound to Python semantics. It is ideal for internal workflows where the producer and consumer are both controlled, but it is a poor fit for data exchange across trust boundaries because the format is capable of carrying instructions for reconstruction, not just values.

Where Pickle Is Useful

Pickle is commonly used for short-lived internal persistence, caching, experiments, and Python-specific state handoff between trusted components. It can capture complex types that would be awkward to encode manually, including nested custom objects.

That convenience can reduce boilerplate, but only when the environment is already trusted and the serialized data has not been exposed to external modification. The practical rule is simple: if the data may be influenced by another user, another service, or an untrusted file source, pickle stops being a convenience and starts becoming an attack surface.

Security Boundaries and Safer Alternatives

Pickle should be treated as unsafe for untrusted input because loading a crafted payload can trigger code execution paths during object reconstruction. A secure design keeps pickle behind a strict trust boundary and avoids using it for public APIs, uploaded files, or cross-tenant data exchange.

When the goal is interoperability or data storage, safer formats such as JSON, MessagePack, or domain-specific schemas are usually better choices because they encode data rather than executable object behaviour. If pickle must be used, the surrounding system should treat the source as fully trusted and the files as sensitive runtime inputs.

Risk and Threat Considerations

Pickle’s primary security risk is that deserialisation can become code execution when an attacker can supply or modify the payload. The issue is not the format alone, but the combination of trusted reconstruction logic and attacker-controlled bytes.

Failure mechanism: A malicious pickle stream can reference callable paths or object hooks that run during unpickling, allowing the payload to escape the intended data-only model.

Impact: This can lead to arbitrary code execution, system compromise, persistence in internal workflows, or supply-chain style abuse where a poisoned file is later loaded by a trusted process.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK addresses the attack and risk surface, while NIST SP 800-53 Rev 5, CIS Controls v8 and SLSA set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
MITRE ATT&CKT1059 — Command and Scripting InterpreterPickle can trigger callable execution during unpickling, aligning with code execution abuse.
Recommendation — Hunt for unexpected interpreter-driven execution paths in Python deserialisation pipelines.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationPickle requires strict trust and input validation because crafted input can alter runtime behaviour.
SI-7 — Software, Firmware, and Information IntegrityPickle payload integrity is essential because tampered objects can execute harmful reconstruction logic.
Recommendation — Validate and reject untrusted serialized input before any deserialisation step. Protect serialized artifacts with integrity checks and only load trusted content.
CIS Controls v8CIS-4 — Secure Configuration of Enterprise Assets and SoftwareUnsafe deserialisation is a software configuration weakness that should be removed or constrained.
Recommendation — Disable or tightly restrict unsafe deserialisation paths in exposed applications.
SLSASupply Chain Levels for Software ArtifactsPickled artifacts can act like poisoned build or runtime inputs in a software supply chain.
Recommendation — Verify artifact provenance before allowing serialized objects into trusted build or runtime flows.

Practitioner Guidance

What to watch for: Treat any use of pickle across a trust boundary as a design warning, especially when the source is a file upload, message queue, cache entry, shared volume, or third-party artifact. The key judgement is whether the data origin is fully controlled and whether a safer data-only format would satisfy the requirement.

Practitioner takeaway: Use pickle only where both sides of the exchange are trusted Python components, and prefer non-executable serialisation whenever the payload might be influenced by someone else.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 12, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org