Skip to content

Deserialization of untrusted data

Description

In Ruby, objects can be serialized into strings using various methods and later reconstituted into objects. The `load` and `object_load` methods, associated with modules like Marshal and CSV, are particularly risky when used to deserialize data from untrusted sources. If an attacker is able to manipulate the serialized data, they could execute arbitrary code on the system when the data is deserialized. This vulnerability can lead to remote code execution (RCE), where an attacker gains the ability to execute commands on the host machine.

Examples

Insecure Code

ruby
Marshal.load(params[:data])

Secure Code

ruby
JSON.parse(json_data, symbolize_names: true)

Remediation

Avoid deserializing from untrusted sources and use JSON for serialization/deserialization instead. Validate and sanitize the input before deserialization.

Rule Details

FieldValue
IDCODE-0524
CategoryDeserialization
SeverityCRITICAL
CWECWE-502
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsdeserialization, ruby, remote code execution
OWASPA8:2017-Insecure Deserialization, A08:2021-Software and Data Integrity Failures

References