Summary
Caddy's FastCGI path splitting logic previously computed the split index on a lowercased copy of the URL path, then applied that index to the original UTF-8 path. Because lowercasing can change the byte length of some Unicode characters, this could cause Caddy to derive incorrect SCRIPT_NAME/SCRIPT_FILENAME and PATH_INFO values.
In configurations where FastCGI is used to execute PHP and attackers can influence on-disk files (e.g., upload areas), this path confusion may cause unexpected PHP execution of non-.php files, which can lead to remote code execution depending on the environment.
Affected context
The vulnerability manifests in Caddy deployments that:
- Use the FastCGI handler to serve PHP (or similar) based on URL paths, and
- Rely on
.phpor similar extensions in the request path to determine which script is executed, and - Handle paths that may include Unicode characters affected by case-folding in UTF-8, and
- Allow attackers some influence over on-disk file contents or locations (e.g., via file uploads or writable directories).
Under these conditions, the mismatch between the lowercased copy used for path splitting and the original path used for slicing can cause Caddy to send a different file to the PHP interpreter than the one the configuration appears to target.
Exploit preconditions
- Attack surface: HTTP(S) request handling in Caddy when routing to a FastCGI backend (commonly PHP-FPM).
- Required access: Ability to send crafted HTTP requests to the server; higher impact if the attacker can also upload or control files in directories that Caddy and the FastCGI backend can access.
- Trigger point: A request path containing specific Unicode characters and
.php(or other FastCGI-targeted suffix) that passes through Caddy's FastCGI path splitting logic. - Why exploitation is possible: The split position for the path is calculated on a lowercased version of the path, but that byte index is applied to the original path string. When
strings.ToLower()changes the UTF-8 byte length of characters before the split point, the computed index no longer aligns with character boundaries in the original string, leading to incorrectSCRIPT_NAME/SCRIPT_FILENAMEandPATH_INFO.
Why this happens
The root cause is a mismatch between logical and byte-level operations during path normalization and splitting, combined with insufficient validation of derived path components.
Specifically, Caddy:
- Lowercased the request path using
strings.ToLower(), which can change the number of bytes used to represent certain Unicode characters in UTF-8. - Calculated the FastCGI split index (e.g., position of
.php) on this modified, lowercased path. - Applied that byte index back to the original path string to derive
SCRIPT_NAME/SCRIPT_FILENAMEandPATH_INFO.
This behavior corresponds to:
- CWE-180: Incorrect Behavior Order: Validate Before Canonicalization, because the system operates on a transformed version of the input and then reuses indices on the original representation, effectively making decisions on one canonical form and applying them to another.
- CWE-20: Improper Input Validation, because the server assumes that the path transformation is length-preserving and that indices calculated on one representation remain valid on the original input without explicit checks.
The insecure pattern, abstractly, is: computing security-critical split points or routing decisions on a transformed string (case-folded, normalized, decoded) and then applying those decisions to a different representation of the input, especially in a multi-byte encoding context.
Potential impact
- Requests containing
.phpin the path may execute a different physical file than the one the configuration seems to target. - Non-.php files under attacker influence could be interpreted as PHP by the FastCGI backend, leading to possible remote code execution when the file contents are treated as executable script.
- Bypass of access controls or routing rules that rely on the intended mapping of URL paths to script files.
- Unexpected disclosure or manipulation of data via execution of unintended scripts or handler logic.
- Increased difficulty for defenders to reason about which requests execute which on-disk resources, complicating audits and incident response.
General mitigation guidance
Resilient mitigation focuses on making path handling Unicode- and encoding-safe, and avoiding ambiguous routing decisions:
- Align transformations and indices:
- Perform all path parsing, extension detection, and splitting on a single, canonical representation of the path.
- Avoid reusing indices computed on transformed strings (lowercased, normalized, decoded) to slice different string representations.
- Unicode-safe normalization:
- Normalize paths in a way that preserves byte offsets when you intend to reuse indices (e.g., operate on runes consistently, or convert both detection and slicing logic to the same representation).
- Treat any transformation that can change length (such as case folding for certain Unicode code points) as non-safe for index sharing.
- Strict FastCGI routing rules:
- Use explicit, configuration-driven script mappings rather than relying solely on dynamic splitting based on path content.
- Constrain which directories and files can be executed by FastCGI with dedicated root/document-root settings.
- Reduce trust in writable areas:
- Avoid allowing FastCGI to execute files from directories where untrusted users can upload or modify content.
- Segregate upload directories from executable script directories, and configure the server so that upload locations are never treated as executable.
- Harden the runtime environment:
- Run FastCGI/PHP workers with least privilege and restrict their filesystem access.
- Apply defense-in-depth controls such as disabling dangerous PHP functions and limiting script execution paths at the interpreter or pool configuration level.
How teams detect issues like this
Security teams can look for this class of issue and its symptoms using a combination of code-focused and behavior-focused approaches:
- Static analysis and code review:
- Flag patterns where indices are computed on a transformed string (e.g., lowercased, normalized) and then applied to the original string or a differently encoded representation.
- Review FastCGI/CGI integration code for manual splitting of
SCRIPT_NAME,SCRIPT_FILENAME, andPATH_INFO, especially in Unicode-aware services. - Look for use of APIs like
ToLower, normalization functions, or decoding routines that precede critical routing decisions without consistent handling of string length and encoding.
- Configuration and policy checks:
- Audit server and FastCGI configurations for execution of scripts in directories that also host user uploads or other untrusted content.
- Enforce policies that disallow treating writable directories as executable roots.
- Runtime and traffic analysis:
- Monitor logs for requests with unusual Unicode paths that contain
.phpor similar script extensions in non-standard positions. - Observe discrepancies between logged request URIs and script filenames reported in backend logs or error traces.
- Automated tooling:
- Incorporate SAST tools and linters that understand Unicode and string-transformation pitfalls into CI/CD pipelines.
- Use dynamic scanning to send crafted Unicode paths through FastCGI endpoints and detect mismatches between expected and actual script execution.

