Using eval() to Process User-Provided Data or Configuration
PHP applications call eval() to execute user-submitted code strings, mathematical expressions, or configuration data treating them as executable PHP code. Common patterns include calculator functionality: eval("return {$_GET['expression']};"); where users submit expressions like 1+1, but attackers inject system('cat /etc/passwd'); or phpinfo(); to execute arbitrary commands. Custom formula evaluators in reporting tools, pricing calculators, or spreadsheet-like applications use eval() to process user-defined formulas: eval('$result = ' . $userFormula . ';');, enabling remote code execution when users control $userFormula. Plugin or module systems that allow users to submit PHP code snippets for customization: eval($userPlugin); intended to execute user extensions but allowing complete system compromise. Content management systems processing shortcodes or template variables through eval(): eval('echo ' . $shortcode . ';'); to dynamically generate content. Admin interfaces for "code execution" or "PHP sandbox" features intended for debugging: eval($_POST['php_code']); which attackers access through privilege escalation or credential theft. The vulnerability is critical because eval() executes PHP code with the full privileges of the web application—file system access, database credentials, session manipulation, and server commands—with no sandboxing or isolation. Attackers gain immediate remote code execution allowing data exfiltration, malware installation, lateral movement to internal networks, or complete server compromise.