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 command 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 dynamic(a,b,c); a + b + c; end"
else
"def dynamic(a,b); a + b; end"
end
get_total = 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')