Summary
Grav contains a PHP code injection vulnerability in Blueprint dynamic-data validation, where an incomplete denylist permits access to a file-writing function. An attacker with page-edit or blueprint-configuration access may append PHP code to a web-accessible file and achieve remote code execution.
Affected context
The vulnerability occurs in Grav deployments that use Blueprint dynamic-data processing and allow users to edit pages or blueprint configuration. It becomes risky when the validation logic relies on a denylist that does not prevent invocation of file-writing functionality, and the application can write to files reachable by the web server.
Exploit preconditions
- Attack surface: Grav page-editing and blueprint-configuration functionality
- Required access: Page-edit or blueprint-config privileges
- Trigger point: Processing a Blueprint dynamic-data directive
- Why exploitation is possible: Incomplete function validation permits a file-writing operation that can append attacker-controlled PHP content to a web-accessible file
Why this happens
The underlying bug is an unsafe function-validation design in which a denylist attempts to block dangerous functions without comprehensively defining permitted behavior. Because a file-writing function remains callable through dynamic data, an authorized but potentially untrusted user can influence server-side files. This maps to CWE-94: Improper Control of Generation of Code, because attacker-controlled input can be written into a location where the application or web server may later interpret it as executable PHP code.
Potential impact
- Attackers may execute arbitrary PHP code with the privileges of the web server
- The Grav installation could be fully compromised
- Sensitive application data and configuration may be exposed
- Attackers could alter content, plant persistence, or tamper with site behavior
- The host or connected services could experience further compromise
General mitigation guidance
Mitigation generally centers on replacing denylist-based dynamic function validation with a positive allowlist of narrowly defined, non-destructive operations.
Common defensive patterns include:
- Permit only explicitly approved functions and data types
- Eliminate dynamic execution and file-writing capabilities from user-controlled directives
- Separate content-editing privileges from blueprint and system-configuration privileges
- Prevent the web process from writing to web-accessible executable directories
- Store user-controlled content outside executable paths where feasible
- Apply least-privilege permissions to the application, filesystem, and hosting environment
- Enforce strict input schemas and authorization checks before processing dynamic data
How teams detect issues like this
Detection approaches may include:
- Static analysis rules for dynamic function dispatch, denylist-based validation, and file-writing APIs used with user-controlled data
- Code review checks for Blueprint directives that can invoke filesystem or execution-related functions
- Monitoring for unexpected changes or appended content in web-accessible PHP files
- File-integrity monitoring on application directories and configuration paths
- Web and application logs showing unusual page-edit or blueprint-configuration activity
- Policy enforcement that blocks application processes from writing executable files in served directories
- Automated security review tools that flag dangerous sinks reached from administrative input

