logo

Database

Ruby Eval Code Injection

Description

Detects potentially dangerous code injection vulnerabilities in Ruby applications where user input could be executed using eval-like methods. This is particularly risky in Sinatra web applications where unvalidated user input might be dynamically evaluated, potentially allowing attackers to execute arbitrary code.

Weakness:

404 - OS Command Injection

Category: Functionality Abuse

Detection Strategy

    Check if the application uses the Sinatra web framework

    Look for calls to dangerous evaluation methods like eval(), instance_eval(), or class_eval()

    Verify if user-controlled input (e.g. request parameters, form data) flows into these dangerous evaluation methods

    Report a vulnerability when user input reaches dangerous evaluation functions without proper sanitization

Vulnerable code example

require 'sinatra'

# Simple user class for demonstration
class User
  def initialize(name)
    @name = name
  end
end...

✅ Secure code example

require 'sinatra'

class User
  def initialize(name)
    @name = name
  end
  
  # Whitelist of allowed methods that can be called...