Potential command injection with user input detected.
- Rule ID: ruby_lang_eval_using_user_input
- Languages: ruby
- Source: eval_using_user_input.yml
Description
It is dangerous to use eval with user input, or to compile code with user-supplied data. Such practices can lead to code injection.
Remediations
❌ Avoid using code execution methods with unsanitized user input.
It might be possible to use dynamic hardcoded values, instead of user input directly.
get_total_str = if params["include_vat"]
"def get_total(a,b,c); a + b + c; end"
else
"def get_total(a,b); a + b; end"
end
cart.instance_eval(get_total_str)
Resources
Associated CWE
- CWE-94: Improper Control of Generation of Code ('Code Injection')
- CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')
OWASP Top 10
Configuration
To skip this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --skip-rule=ruby_lang_eval_using_user_input
To run only this rule during a scan, use the following flag
bearer scan /path/to/your-project/ --only-rule=ruby_lang_eval_using_user_input
Ready to take the next step? Learn more about Bearer Cloud.