Summary
The Grav API plugin contains a file upload validation flaw that allows bypassing the dangerous extensions blocklist by using double extensions such as shell.php.jpg.
When combined with permissive web server configuration and api.media.write privileges, this can result in arbitrary PHP code execution on the server.
Affected context
This vulnerability affects Grav installations that use the Grav API plugin with media write capabilities exposed to users or integrated services.
It is most relevant where uploaded media is stored in a web-accessible directory and the HTTP server is configured to interpret files based on inner or actual executable extensions.
Environments that rely solely on file name extension checks without additional content-type or storage segregation controls are at increased risk.
Exploit preconditions
- Attack surface: Grav API media upload endpoint in the API plugin.
- Required access: Valid account or API client with
api.media.writepermission. - Trigger point: Uploading a file whose name includes a dangerous extension before a benign extension, e.g.,
payload.php.jpg. - Why exploitation is possible: The validation routine inspects only the final extension using
pathinfo($filename, PATHINFO_EXTENSION), so inner dangerous extensions remain unfiltered while the server may still treat the file as executable.
Why this happens
The core issue is an overly simplistic and extension-focused validation check for uploaded files.
The plugin's HandlesMediaUploads::validateFileExtension() function inspects only the last extension segment, assuming that PATHINFO_EXTENSION represents the true risk-bearing type.
This design overlooks filenames with multiple dots where an inner extension corresponds to a server-executable type such as .php.
Conceptually, this maps to CWE-434: Unrestricted File Upload, where insufficient validation of uploaded content, naming, and handling allows attackers to introduce executable or otherwise dangerous files into web-accessible locations.
Potential impact
- Remote execution of arbitrary PHP code on the server.
- Full compromise of the Grav application and its configuration.
- Access to sensitive data stored or managed by the CMS.
- Privilege escalation within the hosting environment depending on server configuration.
- Use of the compromised server as a pivot for further attacks in the network.
General mitigation guidance
Effective mitigation focuses on treating file uploads as untrusted input and constraining both what can be uploaded and how uploads are served.
Defensive patterns include:
- Enforcing strict allowlists of safe, non-executable extensions and rejecting filenames containing multiple extensions or suspicious patterns.
- Validating file content type and structure in addition to extension, avoiding reliance on path-based checks alone.
- Storing uploaded media outside web-executable directories or on a segregated domain that does not interpret server-side code.
- Configuring the web server to disallow execution of dynamic scripts from upload directories.
- Applying least-privilege to accounts and API keys so only trusted principals have media write capabilities.
These measures reduce the risk that a malformed or malicious upload can become an executable payload.
How teams detect issues like this
Detection approaches typically combine code-level inspection and runtime monitoring:
- Static analysis or manual review to flag upload handlers that depend solely on
PATHINFO_EXTENSIONor similar filename-based checks without enforcing strict allowlists. - Reviewing routes and controllers associated with media uploads for missing server-side validation and lack of storage segregation.
- Log analysis to identify unusual upload patterns, such as files containing multiple dots or inner executable extensions (
.php,.phtml,.asp) followed by benign ones. - Security policies in CI/CD that require secure upload handling patterns, including content-type verification and deployment checks ensuring upload directories are non-executable.
Automated tooling can assist by scanning for common unrestricted file upload antipatterns across PHP projects and CMS plugins.

