Dynamic Code Execution (ARCH7131)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key php.security.dynamic-code-execution · Severity critical · Category security · CWE CWE-95
Running a string as code at runtime via eval() is the broadest remote-code-execution primitive. If the input comes from an untrusted source, an attacker can execute arbitrary PHP.
Incorrect
Section titled “Incorrect”<?php$op = $_GET['op']; // e.g. "1+1" or malicious codeeval("\$result = $op;");echo $result;Correct
Section titled “Correct”<?php$allowed = ['add' => fn($a, $b) => $a + $b, 'mul' => fn($a, $b) => $a * $b];$op = $_GET['op'] ?? '';$result = isset($allowed[$op]) ? $allowed[$op]((int)$_GET['a'], (int)$_GET['b']) : null;Avoid eval; replace it with allowlisted operations, parsers, or explicit mapping tables.