phpsafe 𝕏 GitHub
Official CA 421DTkQ3TSG3n7F9SkNZj9NxvdFGbypwkctPd2uupump This is the only official address.

Code execution with eval()

Severity: Critical CWE-95 OWASP A03:2021 Injection rule: eval

Why it matters

eval() runs whatever PHP it receives. If any part of that string comes from a request, an attacker can run their own code on your server.

βœ• Vulnerable
$result = eval('return ' . $_POST['formula'] . ';');
βœ“ Secure
// Allow only known operations
$ops = [
    'add' => fn($a, $b) => $a + $b,
    'sub' => fn($a, $b) => $a - $b,
];
$op = $ops[$_POST['op'] ?? ''] ?? null;
$result = $op ? $op((float)$_POST['a'], (float)$_POST['b']) : null;

How to fix

Never run strings as code. Replace eval with explicit logic, a lookup table or a safe parser.

Scan my code

Paste a file and PHP Safe points to every line that matches this rule.

Scan my code β†’