Skip to content
RCE Write-up Intermediate

Unsafe Deserialization in Ruby Background Workers Leading to Dete

A Ruby background job system deserialised untrusted JSON with Oj.load, which can reconstruct live objects, and then called a method on the resulting object if it responded to it. An attacker could supply a crafted job payload that became a Node object whose run_find method executed arbitrary shell commands in the worker.

nullsecurityx Follow

Published on nullsecurityx.medium.com

This article presents a detailed technical analysis of a Remote Code Execution (RCE) vulnerability caused by unsafe JSON deserialization in a Ruby background job processing system.

NullSecurityX, on nullsecurityx.medium.com

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 application used Oj.load, which reconstructs arbitrary Ruby objects from JSON, and then trusted any deserialised object that responded to run_find to execute it.

Impact

Successful exploitation allows unauthenticated attackers to execute arbitrary commands in background workers, often leading to full system compromise.

What the attacker needed

Ability to submit a background job payload; worker uses Oj.load on the payload; a class with a dangerous method is loaded

The fix

The application should use Oj.safe_load or strict parsing modes, never deserialise untrusted input into objects, replace dynamic dispatch with explicit job handling, and avoid OS command execution with user-controlled arguments.

How it was found

  1. Store a crafted JSON payload as a background job.
  2. Oj.load reconstructs a Node object with attacker-controlled arguments.
  3. The object satisfies the respond_to?(:run_find) capability check.
  4. run_find invokes Open3.capture3("find", *@args).
  5. The operating system executes the find command with injected arguments.
  6. Arbitrary shell commands execute within the background worker context.

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.

JSON is normally just data, like a list of names and numbers. But some Ruby libraries can turn JSON back into real program objects that carry code with them. Here the program trusted that JSON and then ran a method on whatever object appeared, so an attacker could make it run a system command.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by nullsecurityx

View all

6 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.