Tenderlove on Rails security exploits
The article explains how YAML deserialisation in Ruby on Rails could be abused to execute arbitrary code or cause denial of service. An attacker could send a crafted YAML document that instantiates dangerous objects, leading to remote code execution or resource exhaustion.
tenderlovemaking.com
Published on tenderlovemaking.com
YAML seems to be getting a bad rap lately, and I’m not surprised. YAML was used as the attack vector to execute arbitrary code in a Rails process and was even used to steal secrets from rubygems.org.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the YAML parser allowed deserialisation of arbitrary Ruby objects, and application code then called methods on those objects that led to code execution or resource exhaustion.
Impact
An attacker could execute arbitrary code on the server or cause denial of service by exhausting memory or CPU; the text notes that whitelisting classes may prevent code execution but other attacks remain possible.
What the attacker needed
Application deserialises untrusted YAML; attacker can send YAML to the application
The fix
The article argues that a safe YAML loader should only allow basic types (null, booleans, numbers, strings, arrays, hashes) and reject self-referential structures, with an explicit whitelist for any additional classes.
How it was found
- Craft a YAML document that declares a Ruby object of a class present in the application.
- Set the object's instance variables to values that cause dangerous behaviour when a method is called.
- Send the YAML to the application so that it is deserialised and the object is placed in the parameters hash.
- Trigger a method call on the object (e.g., nil? or length) to execute the payload.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
YAML is a text format for storing data, like JSON. In Ruby on Rails, a library called Psych could turn YAML text into live Ruby objects, including ones that run code when used. An attacker could send a malicious YAML file that, when loaded, caused the server to run their commands or crash.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.