Summary
Grav contains a code injection vulnerability in media actions: publishers may bypass the action allowlist by using scoped method names in Markdown image URLs. If crafted content is processed, an attacker may trigger file access or shell command execution with the web server user's privileges.
Affected context
The issue affects Grav versions from 2.0.0 up to, but not including, 2.2.18. It occurs when Markdown image URLs are processed by the media action mechanism and scoped method names can bypass its allowlist, potentially enabling chained calls to static methods.
Exploit preconditions
- Attack surface: Markdown content processed by Grav's media action handling
- Required access: Ability to publish or modify content that the application processes
- Trigger point: Processing an image URL containing a scoped method name
- Why exploitation is possible: The allowlist can be bypassed, allowing chained method calls that may reach command-execution functionality
Why this happens
The media action handling permits scoped method names to evade an action allowlist and be used in chained calls. This is an improper control of dynamically selected functionality, mapping to CWE-94: Improper Control of Generation of Code. The underlying insecure pattern is allowing user-influenced content to select or invoke methods beyond a narrowly defined set of safe actions.
Potential impact
- An attacker may read files accessible to the web server user.
- Shell commands could run with the web server user's privileges.
- The application or its data could be compromised.
- Depending on the server's permissions and environment, an attacker could gain access to additional resources.
General mitigation guidance
Defensive patterns include restricting media actions to a small, explicit set of permitted operations and rejecting scoped or otherwise ambiguous method names. Avoid dynamic method dispatch based on user-controlled content; where such dispatch is necessary, map validated identifiers to fixed handlers. Treat published content as untrusted, constrain command execution, and run the web service with only the privileges it needs.
How teams detect issues like this
Review media action handling for allowlists that can be bypassed through scoped names, alternate method representations, or chained calls. Static analysis and code review can look for user-controlled input flowing into dynamic dispatch, reflection, or shell execution APIs. Content validation policies can reject unsupported method syntax, and runtime monitoring can flag unexpected process creation or file access by the web service. Automated code review tools may help identify these patterns.

