Because the deserializer is allowed to rebuild Python objects, not just read bytes. When that object graph includes callable hooks or attacker-controlled instructions, the load step can execute code under the service’s privileges. In practice, the danger is highest where teams trust internal models, shared caches, or authenticated APIs too much.
Why deserialization becomes an execution boundary
Unsafe deserialization is dangerous because the load step is not always a passive parse. In ML infrastructure, model registries, artifact stores, and orchestration services often deserialize objects that may carry executable behavior, constructors, or references that trigger code during reconstruction. Once that happens, the system is no longer just reading data, it is deciding what code to instantiate and run.
The risk is amplified in ML pipelines because serialized artifacts are often treated as trusted internal assets. A poisoned model file, cache entry, notebook output, or pipeline artifact can cross environment boundaries and reach a service that has file system, network, or cloud permissions far beyond what the attacker originally had.
How attacker-controlled object graphs turn into RCE
The core failure is trusting the object graph instead of validating the data format. Many deserializers can rebuild complex Python objects, not just primitive values, and some object types can invoke hooks, import modules, open files, or call functions as part of normal reconstruction. If the attacker can influence the payload, the deserializer may execute those behaviors automatically.
In ML systems, this is especially risky when the deserialized content is fed into training jobs, inference services, experiment tracking systems, or automated deployment steps. A malicious payload can ride through the same interfaces used for legitimate models and then execute under the privileges of the worker, scheduler, or API service that performs the load.
Why ML infrastructure makes the blast radius larger
ML platforms tend to combine shared storage, reusable artifacts, automation, and broad internal trust. That means a single unsafe load primitive can affect more than one environment if the same model artifact, feature object, or cached result is reused across development, staging, and production. Once execution occurs, the attacker may be able to read secrets, tamper with models, pivot to adjacent systems, or modify downstream outputs.
This is also why authenticated sources are not automatically safe. A compromised internal account, malicious contributor, or tainted upstream dependency can still deliver a payload that the receiving service processes as trusted data. The security question is not only “who uploaded it?”, but “what can the deserializer do when it accepts it?”
Risk and Threat Considerations
Unsafe deserialization creates a code-execution path that often sits behind normal operational trust, so the failure is easy to miss until a payload reaches a privileged loader. In ML infrastructure, that can turn a routine artifact update into full service compromise, secret exposure, or lateral movement into adjacent data and training systems.
Failure mechanism: The application accepts a serialized object format that can reconstruct executable Python objects or invoke hooks during loading, and the payload is allowed to reach a process with meaningful privileges.
Impact: An attacker can trigger remote code execution, then use the service context to access credentials, tamper with models or outputs, and expand into the broader ML environment.
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 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| MITRE ATT&CK | T1027 — Obfuscated Files or Information | Malicious serialized payloads hide executable behavior in data-like content. |
| Recommendation — Inspect serialized artifacts for hidden code paths and suspicious object structures before loading them. | ||
| NIST SP 800-53 Rev 5 | SA-11 — Developer Testing and Evaluation | Unsafe deserialization is a software weakness that requires secure evaluation before release. |
| SI-10 — Information Input Validation | The service must reject untrusted serialized input that can drive code execution. | |
| SC-18 — Mobile Code | Deserializers can instantiate active behavior from imported content, similar to executing mobile code. | |
| Recommendation — Test deserialization paths with malicious inputs before deployment. Validate or forbid unsafe serialized inputs before they reach the loader. Restrict code-bearing content to trusted, tightly controlled execution paths. | ||
| OWASP ASVS | V15 — Secure Coding and Architecture | Safe design should avoid deserialization mechanisms that can instantiate arbitrary objects. |
| Recommendation — Use data-only formats and remove arbitrary object reconstruction from load paths. | ||
Practitioner Guidance
What to prioritise: Treat every deserialization boundary as an execution boundary until proven otherwise. The first question is whether the service truly needs rich object reconstruction, or whether a safer data-only format can replace it.
What to verify: Confirm that model loading, cache hydration, and artifact import paths reject arbitrary object types, fail closed on unexpected classes, and run with the minimum privileges needed for the task. Review whether internal APIs, signed artifacts, or trusted buckets are being used as implicit security controls, because trust in the source does not neutralize a dangerous parser.
Decision rule: If a payload can influence class selection, constructor behavior, or import resolution during load, treat the path as remote code execution exposure and prioritise containment, format restriction, and privilege reduction before convenience or performance tuning.
Practitioner takeaway: In ML infrastructure, the main control objective is not merely to “validate input”, but to prevent deserialization from becoming an implicit execution channel in a privileged service.
Related resources from NHI Mgmt Group
- Why do unsafe XSLT processing settings create remote code execution risk in metadata catalog platforms?
- Why do unsafe SpEL expressions create both remote code execution and denial-of-service risk in Spring applications?
- Why does insecure object deserialization create such high-risk remote code execution exposure in application servers?
- Why does Lambda deserialization create code execution risk in ML pipelines?
Deepen Your Knowledge
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.
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