Looking for the vulnerability index of Invicti's legacy products?
Code Evaluation (Ruby) - Vulnerability Database

Code Evaluation (Ruby)

Description

This application is vulnerable to Ruby code injection, a critical security flaw that allows attackers to execute arbitrary Ruby code on the server. This vulnerability occurs when user-controlled input is passed directly to dangerous evaluation functions like eval(), instance_eval(), or class_eval() without proper validation or sanitization. When exploited, attackers can manipulate the input to inject malicious Ruby code that will be executed with the same privileges as the application.

Remediation

Eliminate the use of dynamic code evaluation functions with user input. Follow these remediation steps:

1. Remove dangerous evaluation functions: Avoid using eval(), instance_eval(), class_eval(), and module_eval() with any user-controlled input.

2. Use safe alternatives: Replace dynamic evaluation with safer approaches such as:

# Instead of eval() with user input:
# UNSAFE: eval(params[:code])

# Use whitelisting for allowed operations:
ALLOWED_OPERATIONS = {
  'add' => ->(a, b) { a + b },
  'multiply' => ->(a, b) { a * b }
}

operation = ALLOWED_OPERATIONS[params[:operation]]
result = operation.call(param1, param2) if operation

3. Implement input validation: If dynamic behavior is absolutely necessary, use strict whitelisting to allow only predefined, safe values. Never trust user input.

4. Apply the principle of least privilege: Run your application with minimal necessary permissions to limit the impact of potential exploitation.

Related Vulnerabilities