Ruby Use Of Marshal Dangerous Function
Description
This detector identifies dangerous use of Ruby's Marshal class for deserialization operations. Marshal.load() and similar methods can execute arbitrary code when deserializing untrusted data, leading to remote code execution vulnerabilities.
Detection Strategy
• Scans Ruby source code files (excluding test files) for method calls on the Marshal class
• Identifies calls to dangerous Marshal methods like 'load', 'restore', or other deserialization operations
• Checks if the first argument to the Marshal method comes from an unsafe source (user input, external data, etc.)
• Reports a vulnerability when Marshal deserialization methods are called with potentially untrusted data that hasn't been properly sanitized
Vulnerable code example
require 'base64'
class RestoreController < ApplicationController
def case_1
Marshal.load(params[:state]) # Direct deserialization of user input - RCE risk
end
def case_2...✅ Secure code example
require 'base64'
require 'json'
class RestoreController < ApplicationController
def case_1
JSON.parse(params[:state]) # Use JSON instead of Marshal for user input
end
...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.