Summary
A remote code execution vulnerability in the Grav API plugin can let users with publisher-level media and page write rights upload files into a theme's Twig templates folder. If a page includes an uploaded template through the blueprint-upload functionality, commands may run with the web-server user's privileges.
Affected context
The issue affects the Grav API plugin in versions from 1.0.0 up to, but not including, 1.1.4. It occurs when the blueprint-upload endpoint permits a publisher with media and page write rights to write files into a theme's Twig templates folder, and a page can include the uploaded template.
Exploit preconditions
- Attack surface: Grav API blueprint-upload endpoint
- Required access: Publisher-level rights to write media and pages
- Trigger point: An uploaded template is included from a page's Twig content
- Why exploitation is possible: The upload path allows a user with those rights to place a file in a theme template location where it can be interpreted during rendering
Why this happens
The underlying issue is insufficient control over where uploaded files can be written and how they are later interpreted. Allowing a publisher-controlled upload to reach a Twig template location can turn file content into executable template logic, mapping to CWE-94: Improper Control of Generation of Code.
Potential impact
- Commands could execute as the web-server user
- The Grav application and its accessible data may be compromised
- An attacker could alter site content or disrupt site availability
- The web server's permissions could allow further access to connected systems or resources
General mitigation guidance
Mitigations generally focus on separating user-managed uploads from executable template locations and limiting which roles can write files used by the application.
Common defensive patterns include:
- Store uploaded media outside template and code directories
- Restrict upload destinations and file types using server-side policy
- Keep template authoring and deployment under trusted, privileged control
- Treat user-managed content as untrusted and avoid interpreting it as executable templates
- Run the web server with only the permissions it needs
How teams detect issues like this
High-level detection approaches include:
- Review upload handlers for user-controlled paths that can reach template or code directories
- Use static analysis to flag file-write operations involving executable template locations
- Monitor for unexpected changes to theme template files and review the identity responsible
- Enforce policies that separate media-upload permissions from template modification permissions
- Include authorization and upload-destination checks in security reviews and automated testing

