Skip to main content
CriticalCodeOWASP A03:2021CWE-94

How to fix: PHP assert()/create_function() Code Execution Risk

PHP's assert() is called with user-controlled input, or the deprecated create_function() (which internally uses eval()) is present.

Why it matters

In PHP versions before 8, assert() evaluates a string argument as PHP code, identical in effect to eval(); passing user input to it is a direct remote code execution vector.

assert() was historically documented as accepting either a boolean expression or a string to be eval()'d, a design PHP itself later reversed (PHP 8 removed string evaluation) precisely because of how often it was exploited. create_function() has the same underlying eval()-based implementation and was removed entirely in PHP 8.

How to fix it

  1. 1Never pass request-derived data to assert().
  2. 2Replace create_function() with a native anonymous function or arrow function.
  3. 3Upgrade to PHP 8+, where assert() no longer evaluates string arguments as code.

Code examples

Replace unsafe patterns

PHP
// BAD
assert($_GET['check']);
$fn = create_function('$a', 'return $a + 1;');

// GOOD
if (!isSomeCondition($validatedInput)) { throw new InvalidArgumentException(); }
$fn = function ($a) { return $a + 1; };

References

Detected automatically by VulnRadar. The check id is code-eval-php-assert-string, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is PHP assert()/create_function() Code Execution Risk?
VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id code-eval-php-assert-string, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does PHP assert()/create_function() Code Execution Risk map to?
It maps to CWE-94. In the OWASP Top 10 it falls under A03:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for php assert()/create_function() code execution risk

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

PHP assert()/create_function() Code Execution Risk | VulnRadar