Join our Newsletter — 33% off our NHI Course

Binary Deserialisation

Binary deserialisation is the process of rebuilding Ruby objects from a binary encoded payload, commonly through Marshal.load. It becomes dangerous when the payload is untrusted, because crafted object chains can trigger unintended method calls during object reconstruction and lead to remote code execution.

What Binary Deserialisation Actually Does

Binary deserialisation turns a compact binary payload back into live Ruby objects. In normal use, that is a convenience feature for application state, but it also means the runtime is executing object-construction logic, not just parsing inert data.

The important security point is that deserialisation is not always a neutral data conversion step. In Ruby, object graphs can carry enough structure and type information to influence how objects are rebuilt, which is why unsafe deserialisation can become a code execution path rather than a simple decoder.

Why Marshal.load Is the Usual Danger Point

The strongest risk comes from loading attacker-controlled data through mechanisms such as Marshal.load. That API is designed for Ruby object reconstruction, so it trusts the payload to describe legitimate object state and relationships.

When the source is untrusted, that trust becomes the problem. A crafted payload can embed object chains that reach surprising methods during reconstruction, especially when classes define custom behaviour that runs as part of allocation, comparison, conversion, or callback-style logic.

This is why binary deserialisation sits in the same broad family as insecure deserialisation bugs in other ecosystems: the issue is not the binary format itself, but the fact that the format can carry executable object semantics if the application accepts hostile input.

How Object Chains Turn Data Into Behaviour

Binary payloads become dangerous when the object graph includes gadgets, or classes whose normal methods have side effects that are useful to an attacker. During reconstruction, the runtime may invoke methods needed to rehydrate or validate the object, and those calls can cascade through other objects.

That cascade is what makes the vulnerability practical. The attacker is not trying to “corrupt a file” in the abstract, but to guide the deserialiser into a sequence of method calls that ends in unexpected file access, command execution, network interaction, or other unsafe behaviour.

Defensive review therefore has to focus on the deserialisation boundary itself, plus any reachable classes that become callable during object rebuild. In security terms, the payload is both data and a control surface.

Safer Patterns for Handling Binary Payloads

Binary serialisation is not inherently bad, but it should be reserved for trusted, internal, tightly controlled data flows. If the payload can cross a trust boundary, the deserialiser should be treated as a high-risk sink rather than a convenience API.

Where possible, use explicit schema-based parsing, strict allowlists of permitted types, or formats that do not reconstruct arbitrary language objects. If a Ruby application must preserve objects, the safer design goal is to deserialize only known structures from trusted sources and keep object construction separate from untrusted input handling.

For teams that need a practical reference point, the general control emphasis in NIST SP 800-53 Rev 5 Security and Privacy Controls is to protect system integrity and constrain unsafe code paths, while OWASP API Security Top 10 is useful where deserialised objects feed exposed application interfaces.

Risk and Threat Considerations

Binary deserialisation becomes a serious security issue when untrusted payloads can influence object construction. The main risk is remote code execution, but the same flaw can also expose file-system access, denial of service, or unexpected internal calls that were never meant to be reachable from user input.

Failure mechanism: A crafted binary payload supplies an object graph that triggers gadget methods during reconstruction, allowing attacker-controlled execution flow inside the application process.

Impact: Successful exploitation can lead to code execution, data theft, service compromise, or full application takeover if the deserialiser runs with meaningful privileges.

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
NIST SP 800-53 Rev 5 SI-10 — Information Input Validation Binary deserialisation accepts attacker-controlled input that must be constrained before use.
SI-16 — Memory Protection Unsafe object reconstruction can lead to code execution and process compromise.
AC-6 — Least Privilege A deserialisation compromise is less damaging when the process has minimal authority.
Recommendation — Validate serialized input before processing it. Harden execution paths that could be abused by deserialisation flaws. Run deserialising services with the minimum required privileges.
OWASP ASVS V5 — File Handling Binary payload handling is a file and data parsing problem that can become unsafe object reconstruction.
Recommendation — Restrict accepted binary data formats and reject untrusted object streams.
MITRE ATT&CK T1059 — Command and Scripting Interpreter Deserialisation flaws can end in interpreter or command execution on the target system.
Recommendation — Map deserialisation compromise to execution techniques during threat hunting.

Practitioner Guidance

Common misunderstanding: Do not treat binary deserialisation as a safer alternative to text parsing. The format may be compact, but the security question is whether it reconstructs executable language objects from data that can be influenced by an attacker.

What to watch for: Audit every place where binary payloads enter the application, especially session stores, caches, message queues, and any endpoint that accepts serialized Ruby data. If the data path is not fully trusted, deserialisation should be assumed unsafe until proven otherwise.

Practitioner takeaway: The safest default is to avoid deserialising untrusted binary objects at all, and to design the data boundary so that parsing cannot invoke application behaviour.