Unsafe deserialisation breaks the assumption that API payloads are passive data. In AI serving stacks, a crafted request can become code execution, memory corruption, or a crash before any model-level safety control has a chance to act. The practical failure is at the boundary where the runtime trusts the payload too early.
Why This Matters for Security Teams
unsafe deserialisation is not just a coding defect. In AI serving APIs, it can turn a request body into an execution path, which means the failure happens before model guardrails, prompt filters, or policy checks ever see the traffic. That changes the threat model from “bad input” to “runtime compromise,” especially in inference gateways, model routers, and orchestration services that deserialize complex objects or accept rich serialization formats.
The practical risk is that AI stacks often sit on high-value infrastructure with access to models, secrets, caches, and downstream tools. Once deserialization is unsafe, attackers may trigger denial of service, alter execution flow, or plant code paths that expose credentials and training artifacts. NIST guidance on identity and access control is still relevant here, but it only helps if the application boundary survives long enough to enforce it, as reflected in NIST SP 800-63 Digital Identity Guidelines and NIST SP 800-53 Rev 5 Security and Privacy Controls.
NHIMG research shows how fast AI-adjacent exposures become operational incidents, including the DeepSeek breach, which illustrates how exposed data and platform weakness combine into a broader compromise. In practice, many security teams discover unsafe deserialisation only after the serving API has already crashed or been used as a foothold into the wider AI environment.
How It Works in Practice
AI serving APIs often receive structured payloads that travel through web frameworks, RPC layers, job queues, or message buses before reaching the model. If any layer reconstructs objects unsafely, the attacker may control type resolution, gadget chains, or object state in a way that causes unexpected code paths. In plain terms, the API is no longer parsing data. It is instantiating behaviour.
That breaks several assumptions security teams make about AI systems:
- The request is no longer harmless until validated, because validation may never run if deserialisation fails first.
- Model-level controls such as prompt filtering or output moderation do not help if the runtime is compromised at the transport boundary.
- Secrets held by the serving process, including API keys and credentials, become reachable if the attacker gets code execution.
- Availability suffers quickly because crashes, memory corruption, and resource exhaustion can take down inference traffic.
For this reason, current guidance favors strict allowlists of serialisation formats, schema validation before object construction, and isolation of the serving process from sensitive secrets. Practitioners should also treat model gateways, feature stores, and worker pools as separate trust boundaries. Where possible, keep the inference container minimal, avoid complex native deserialisers, and use defensive controls that reduce blast radius if parsing is abused. The same operational lesson appears in NHIMG’s reporting on default credential abuse, including McDonald’s McHire AI Chatbot Default Credentials, which shows how quickly AI-facing systems fail once the boundary is weak.
Where teams need stronger validation at the API edge, pairing input schema checks with runtime hardening and identity-aware access control is a pragmatic baseline, but it only works if deserialisation happens in a non-privileged path. These controls tend to break down when legacy Python, Java, or .NET services accept untrusted polymorphic objects because the framework itself may instantiate attacker-influenced types before custom validation logic executes.
Common Variations and Edge Cases
Tighter deserialisation controls often increase development and compatibility overhead, requiring organisations to balance security against integration flexibility. That tradeoff becomes sharper in AI environments where teams mix model servers, plugin frameworks, and third-party middleware.
Some teams assume “safe” formats such as JSON eliminate the risk. That is not always true. Unsafe deserialisation can still appear when JSON is mapped into rich objects, when type metadata is accepted from the client, or when a parser hands attacker-controlled values to downstream libraries. Best practice is evolving here, and there is no universal standard for every framework.
Edge cases also matter in environments that use sidecar proxies, serverless functions, or distributed inference pipelines. A payload may be validated in one component and then reconstructed unsafely in another. In those cases, security teams should look for deserialisation at every hop, not just at the public API. That includes model tool adapters, job replay systems, and admin endpoints that are often overlooked during design reviews.
Operationally, the safest pattern is to minimize object construction from untrusted input, prefer simple data transfer objects, and keep high-privilege credentials out of the serving process entirely. If a service must deserialize complex structures, it should do so with explicit type allowlists, strict versioning, and monitoring for abnormal parser failures. The key question is not whether the payload is valid enough to parse, but whether the parser can be trusted to remain non-executable under attack.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10, CSA MAESTRO and OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST AI RMF and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | Unsafe deserialisation can let AI-serving code execute attacker-controlled behavior. | |
| CSA MAESTRO | MAESTRO covers runtime trust boundaries for autonomous and AI-driven workloads. | |
| NIST AI RMF | AIRMF applies to systemic AI risk when service integrity and availability fail. | |
| NIST CSF 2.0 | PR.PT-3 | Protective technology should stop unsafe parsing before it becomes execution. |
| OWASP Non-Human Identity Top 10 | NHI-01 | AI APIs often expose secrets once deserialisation yields code execution. |
Treat agent and serving inputs as hostile, and block object creation from untrusted payloads.
Related resources from NHI Mgmt Group
- What breaks when AI coding agents are allowed to run Git operations on untrusted repositories?
- What breaks when organisations only secure the model layer of agentic AI?
- What breaks when AI tools can execute local code through delegated access?
- How should teams reduce the risk of exposed AI credentials being abused?