Zennoxa Shield
Rules / Ruby
SHIELD-RUBY-012

Unsafe deserialization via Marshal.load

criticalRubyCWE-502CVSS 9.8

What it detects

Marshal.load on untrusted data can instantiate arbitrary objects and execute code.

How to fix

Never deserialize untrusted data with Marshal; use JSON with a strict schema instead.

Vulnerable — Shield flags thissession_cache.rb
class SessionCache
  def read(key)
    raw = redis.get(key)
    Marshal.load(raw) if raw
  end
end
Fixed — scans cleansession_cache.rb
require "json"

class SessionCache
  def read(key)
    raw = redis.get(key)
    JSON.parse(raw, symbolize_names: true) if raw
  end
end

Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-RUBY-012, the fixed one does not.

SHIELD-RUBY-012: Unsafe deserialization via Marshal.load — Zennoxa Shield