Join our Newsletter — 33% off our NHI Course
Home› Glossary› Cyber Security› CWE-502
Cyber Security

CWE-502

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

CWE-502 is the Common Weakness Enumeration entry for deserialisation of untrusted data. It covers cases where software accepts structured data and reconstructs objects without sufficient validation, allowing tampering, unexpected method calls or code execution through crafted input.

What CWE-502 Means in Practice

CWE-502 describes a weakness in which software deserialises structured input from an untrusted source without enough validation. The danger is not the data format itself, but the act of turning attacker-controlled bytes into live objects with behaviour.

This matters because deserialisation often happens deep inside application plumbing, where developers assume the input is already safe. Once object state is reconstructed, fields, types, and method paths can influence control flow in ways that are hard to see in code review alone.

Why Untrusted Deserialisation Becomes Dangerous

When a parser accepts object graphs, type metadata, or polymorphic payloads from outside the trust boundary, the attacker may be able to change program behaviour rather than just corrupt a value. That can lead to object injection, unexpected method invocation, privilege abuse, or remote code execution, depending on the language and gadget surface.

The risk increases when the application trusts opaque frameworks, legacy serialisation formats, or automatic type resolution. In those cases, the vulnerability is often caused by an unsafe design assumption: that incoming data can be treated as if it were already internal state.

For a deeper taxonomy of the weakness itself, the Insecure Deserialisation Guide explains common object-injection patterns and language-specific failure modes.

How Teams Find and Contain Exposure

Exposure review starts with locating every code path that accepts serialised input, including APIs, queues, session stores, caches, task payloads, and inter-service messages. Asset inventory matters because deserialisation bugs are often spread across frameworks and shared libraries, not isolated to one endpoint.

Teams should also check whether any of those paths are internet-facing or reachable through less trusted integrations. Vendor advisories, dependency manifests, and framework defaults are important here, because many deserialisation flaws are introduced through platform features that look convenient until a hostile payload reaches them.

The broader CWE Top 25 Guide is useful for placing CWE-502 in the wider landscape of root-cause weaknesses, while the CVE, CWE and CPE Guide helps teams connect weakness classes to concrete affected products and advisories.

Safer Design and Remediation Patterns

The safest response is to avoid accepting arbitrary object graphs at all. Where deserialisation is required, use fixed-type contracts, strict allowlists, safe loaders, and formats that do not permit attacker-chosen behaviour. The objective is to keep data as data, not executable structure.

Remediation should also include checking whether older serialisation mechanisms can be removed entirely, since many exploitable paths persist because they are legacy conveniences. In practice, the same application may need a code fix, a framework configuration change, and a contract redesign to fully close the issue.

For teams standardising their approach, the Secure Deserialisation Guide gives a practical engineering view of fail-closed loader settings and safer language-specific defaults.

Detection, Review, and Assurance After Exposure

If a deserialisation flaw may have been reachable, detection should look for suspicious payload shapes, unusual object types, unexpected method execution, and follow-on actions that do not match normal application behaviour. Logs alone may not prove compromise, because the most serious outcome is often hidden in a successful object reconstruction step.

After a fix, teams should review whether the weakness was exploited before patching. That means checking for abnormal process launches, suspicious outbound connections, strange session behaviour, or unexpected changes made through the affected service path. Where the deserialised object could carry authentication material or session state, rotate the relevant credentials or invalidate affected sessions as part of the post-incident response.

For application-security governance that treats deserialisation as an integrity issue, the OWASP Top 10 A08 Guide shows how this weakness fits into software and data integrity failures.

Standards & Framework Alignment

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

OWASP ASVS and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV5 — File HandlingDeserialisation accepts structured input that must be safely handled before object reconstruction.
V15 — Secure Coding and ArchitectureCWE-502 is a code-level trust-boundary failure requiring safer architecture and coding patterns.
Recommendation — Verify deserialisation paths enforce strict type handling and reject untrusted object material. Redesign unsafe serialisation flows so untrusted data cannot drive object behaviour.
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationUntrusted deserialisation is a validation failure at a security-sensitive input boundary.
SI-7 — Software, Firmware, and Information IntegrityThe weakness can enable tampering and code execution through crafted object data.
SA-11 — Developer Testing and EvaluationThis weakness is commonly found through security testing of application input paths.
Recommendation — Validate and constrain structured input before it is reconstructed into application objects. Use integrity checks and trusted loaders to block manipulated serialised data. Test deserialisation paths for unsafe object creation and gadget-chain behaviour.

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 28, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org