Summary
FrankenPHP contains a path parsing flaw where the splitPos() function mishandles non-ASCII bytes when performing case-insensitive matching, allowing non-.php files to be treated as PHP scripts.
In deployments where attackers can upload or otherwise place files on the server, they can craft URLs that trigger this confusion and potentially achieve remote code execution.
Affected context
This vulnerability affects FrankenPHP deployments using the CGI-style routing logic implemented in cgi.go, specifically versions 1.11.2 through 1.12.2.
It appears in environments where:
- FrankenPHP inspects request paths to decide whether a resource should be executed as PHP or served as static content
- Non-ASCII bytes in URLs are accepted and passed through to the router
- Users can upload or otherwise influence files that are later served by FrankenPHP (such as media uploads, document storage, or user-generated content)
The issue is tied to how the server determines ".php" extensions under case-insensitive matching, so it is most risky when extension-based routing is relied upon for security.
Exploit preconditions
- Attack surface: HTTP(S) interface exposed by FrankenPHP, including any endpoints that accept or serve user-controlled files.
- Required access: Ability to upload or place arbitrary content into files that FrankenPHP will serve (e.g., authenticated uploads, multi-tenant storage, misconfigured public write directories).
- Trigger point: An HTTP request whose path contains at least one non-ASCII byte and matches specific patterns that confuse splitPos() into misclassifying the target file as a PHP script.
- Why exploitation is possible: The splitPos() function uses
golang.org/x/text/searchwithsearch.IgnoreCasein a way that does not account for non-ASCII normalization and comparison semantics, causing incorrect detection of the.phpsuffix and leading the server to execute content that should be treated as static.
Why this happens
The underlying issue is improper input validation and canonicalization in the path parsing logic that decides which requests are routed to the PHP interpreter.
The splitPos() function relies on a case-insensitive search over raw request paths and assumes ASCII-oriented behavior, but non-ASCII bytes interact with golang.org/x/text/search in ways that the code does not anticipate.
This misalignment between the comparison model and the actual byte-level path leads to incorrect identification of the .php extension, mapping primarily to CWE-20: Improper Input Validation, with aspects of CWE-176: Improper Handling of Unicode Encoding and CWE-178: Improper Handling of Case Sensitivity.
Abstractly, the pattern is: security-sensitive decisions (script vs static) are made on non-normalized, locale-sensitive string operations instead of strict, canonical extension checks on a validated path representation.
Potential impact
- Non-PHP files may be incorrectly treated and executed as PHP scripts.
- Attackers who can control file contents may execute arbitrary PHP code on the server.
- Compromise of application data, including reading or modifying sensitive information.
- Escalation from a simple file upload capability to full remote code execution.
- Potential pivot to broader system compromise depending on PHP configuration and host hardening.
General mitigation guidance
Mitigation should focus on making path and extension handling deterministic, byte-safe, and independent of locale or complex case-folding rules.
Useful patterns include:
- Performing extension checks on a canonical, normalized path using simple, ASCII-aware comparisons rather than locale-dependent search utilities.
- Decoupling routing from raw user input by mapping requests to an internal, sanitized resource representation before deciding execution behavior.
- Treating all user-uploaded or user-controlled files as non-executable by default, and segregating upload directories from script directories.
- Applying least-privilege principles to the PHP runtime (e.g., restricted file system access and disabled dangerous PHP functions) to reduce impact if misclassification occurs.
- Using defense-in-depth controls such as web server rules that explicitly prevent execution from upload paths, regardless of application behavior.
How teams detect issues like this
Detection can rely on a combination of code-centric and behavior-centric approaches:
- Static analysis rules that flag security decisions based on complex, locale-aware or Unicode-sensitive string APIs instead of simple, canonical comparisons for extensions.
- Code review patterns focusing on routing logic and file serving paths, verifying that
.phpdetection is based on normalized, byte-level checks and that Unicode and case handling are consistent. - Automated tests that exercise routing with paths containing non-ASCII bytes, mixed case extensions, and unusual encodings, verifying that only intended files are executed as PHP.
- Runtime monitoring and web application firewalls that look for suspicious access patterns to uploaded content, especially requests with unusual encodings that cause non-PHP files to be treated as dynamic.
- Integration of automated security review tools into CI/CD pipelines to highlight changes to URL parsing, routing, and upload handling logic.

