Unsanitized user input in 'eval' type function

Description

Executing code with 'eval' or similar functions using unsanitized user input is risky and can lead to code injection vulnerabilities. This happens when external input is used directly in functions that execute code, allowing attackers to run malicious code within your application.

Remediations

  • Do not use 'eval' or similar functions with user-supplied data. This can open your application to severe security risks.
    eval("echo " . $_GET["untrusted"]);  // unsafe
  • Do validate and sanitize all user input before using it in your code. Ensure that the input does not contain malicious code or commands.
  • Do use safer alternatives to 'eval' for dynamic code execution. Consider using functions that limit the scope and capabilities of executed code to reduce risk.

References

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=php_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=php_lang_eval_using_user_input