Unsanitized user input in 'eval' type function

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

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