Unsafe serialization is the use of file formats or deserialization methods that can execute embedded code when a model or object is loaded. In AI environments, formats such as pickle or joblib can become attack paths if untrusted artifacts are accepted. The risk is code execution disguised as data handling.
Expanded Definition
Unsafe serialization is not just a formatting issue. It is a trust-boundary failure where software treats structured input as inert data even though the parser or loader may reconstitute executable behaviour during object creation. The primary concern is not the file extension or storage medium, but whether the deserialiser can instantiate attacker-controlled classes, invoke hooks, or resolve references with side effects.
In AI and data-processing environments, the boundary matters because model artefacts, caches, checkpoints, and inter-service payloads are often exchanged with assumptions about provenance and integrity. A format such as pickle or joblib becomes dangerous when an organisation accepts it from an untrusted source or validates it too late. Guidance on safe identity and trust assumptions is distinct from the core issue here, so the primary lens remains secure software handling rather than identity governance.
A common misunderstanding is to treat deserialisation risk as equivalent to generic file-upload risk. The real distinction is whether loading the artefact itself can trigger execution, even before application logic inspects the content. That is what makes unsafe serialization a code-execution problem disguised as data processing. For a broader control perspective, NIST’s security control catalogue is useful where teams need to tie this weakness to application hardening and software supply-chain controls, and the official source is the most direct starting point: NIST SP 800-53 Rev 5 Security and Privacy Controls.
Examples and Use Cases
Unsafe serialization appears wherever systems exchange complex Python objects or other language-native structures and assume the loader is trustworthy. The same pattern can be present in model pipelines, internal automation, and distributed services.
- A data science platform loads a joblib checkpoint from a shared bucket without verifying who produced it.
- An MLOps workflow restores a pickled pipeline artifact during deployment, and the restore step runs code embedded in the object graph.
- A service accepts a serialized message from a partner integration and deserialises it before authenticating the sender’s intent.
- An internal cache or task queue stores object blobs that are later rehydrated by another process with higher privileges.
- A notebook user imports a “model helper” file that looks like data but contains executable reconstruction logic.
The trade-off is convenience versus safety. Native object formats preserve developer productivity and complex state, but they also collapse the separation between data and behaviour. In environments with frequent artifact exchange, that convenience often hides the most important question: can the loader prove the artefact is trusted before it is parsed?
Security Implications
When unsafe serialization is misunderstood, the failure mode is often remote code execution at load time, not after an obvious exploit chain. That means the dangerous payload may execute during routine operations such as startup, model restore, cache warming, or batch processing, which makes the compromise blend into normal administration.
Other consequences follow quickly. A loaded object can alter local files, steal environment variables, pivot into cloud credentials, tamper with model weights, or modify downstream data. In AI systems, the blast radius can include poisoned model serving, compromised training jobs, and loss of trust in artefact provenance. Because the exploit is delivered as a legitimate-looking object, standard content review can miss it unless teams inspect the deserialisation boundary itself.
Practitioners should watch for any workflow where an artefact is accepted from outside the current trust domain and then reconstructed by an interpreter with execution capability. The observable symptom is often an unusually powerful loader path that receives far more trust than the source of the file deserves.
Domain and Governance Relevance
Unsafe serialization matters most in software and AI supply chains, where artefacts move between training, packaging, deployment, and automation stages. The governance question is not whether the file is “data” or “code” in name, but whether the platform allows a data-loading step to inherit code execution privileges.
For AI teams, the risk becomes sharper when model files, feature pickles, or pipeline snapshots are shared across environments with different trust levels. That can turn an ordinary deployment mechanism into an execution channel. This is one reason NHI-adjacent controls become relevant only at the boundary: the issue is not identity in the abstract, but the fact that a deserialised object may gain access to secrets, service endpoints, or automation permissions after load.
Governance should therefore treat unsafe serialization as a lifecycle control problem spanning artifact provenance, approved formats, and loader restrictions. The practical objective is to ensure that trusted execution is never implied by an untrusted data source.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK address the attack and risk surface, while CIS Controls v8, NIST CSF 2.0 and NIST AI 600-1 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| CIS Controls v8 | 16 — Application Software Security | Unsafe serialization is an application-level code execution weakness. |
| 8 — Audit Log Management | Deserialization abuse is easier to detect with loader and artifact logs. | |
| Recommendation — Apply secure coding and input handling reviews to remove unsafe deserialization paths. Log artifact sources and deserialization events for investigation and traceability. | ||
| NIST CSF 2.0 | PR.DS — Data Security | Serialized artifacts need integrity and trust controls before loading. |
| Recommendation — Enforce artifact integrity checks before any deserialization step. | ||
| MITRE ATT&CK | T1027 — Obfuscated Files or Information | Malicious payloads can hide executable behavior inside data-looking files. |
| Recommendation — Inspect suspicious serialized artifacts for embedded execution logic before loading. | ||
| NIST AI 600-1 | 3.3 — Model and Dataset Integrity | AI artifacts can be subverted when unsafe loaders accept untrusted objects. |
| Recommendation — Validate model and dataset artifacts through trusted serialization formats only. | ||
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 10, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org