Summary
ThinkPHP's Dispatcher can evaluate attacker-controlled PHP expressions while parsing PATH_INFO because it uses preg_replace with the /e modifier and a double-quoted replacement. An unauthenticated attacker who can send a crafted request with a malicious s parameter may execute arbitrary code on the server.
Affected context
The vulnerability is described in ThinkPHP 2.0 through 2.2 and ThinkPHP 3.0 Lite mode, in Dispatcher PATH_INFO parsing. It becomes risky when the affected code processes attacker-controlled request parameters through the vulnerable preg_replace expression and the application endpoint is reachable.
Exploit preconditions
- Attack surface: An HTTP endpoint running an affected ThinkPHP configuration
- Required access: No authentication is required, according to the vulnerability description
- Trigger point: Request handling in
index.phpwhen parsing thesparameter - Why exploitation is possible: The parsing expression evaluates a replacement containing attacker-controlled PHP expressions
Why this happens
The underlying bug is the use of preg_replace with the /e modifier and a double-quoted replacement in request parsing. This pattern evaluates the replacement as PHP code rather than treating input purely as data, mapping to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code.
Potential impact
- An attacker may execute arbitrary code with the privileges of the web server process.
- The application and its accessible data could be compromised.
- An attacker could modify application files or disrupt service.
- If the web server has excessive permissions, compromise could extend to other resources in its environment.
General mitigation guidance
Defensive patterns include removing dynamic evaluation from request parsing and using ordinary string or routing operations instead. Treat request parameters as untrusted data, validate them against a narrow expected format, and avoid constructing executable expressions from user input. Where dynamic behavior is necessary, use constrained mappings and run the application with least-privilege permissions.
How teams detect issues like this
Review request-parsing code for preg_replace calls using the /e modifier, especially when replacement strings include request-derived values or double-quoted interpolation. Static analysis and code review can flag dynamic evaluation functions and data flows from HTTP parameters into executable contexts. Policy checks can prohibit deprecated evaluation patterns and require validation of externally supplied routing values.

