Summary
The Grav Flex Objects plugin before version 1.4.0 contains a stored server-side template injection vulnerability in how dynamic collection and object titles are rendered.
By controlling specific frontmatter title fields, an attacker can inject Twig template code that Grav evaluates on the server, potentially leading to remote command execution through internal Grav services.
Affected context
This vulnerability appears in Grav installations that use the bundled Flex Objects plugin to serve publicly reachable pages where frontmatter titles are derived from user-influenced content.
The problematic behavior occurs when page.header.flex.collection.title or page.header.flex.object.title values are passed to Twig::template_from_string() and evaluated as templates rather than plain text.
Deployments that allow editors, integrators, or other users to define or modify these frontmatter fields without strict sanitization or review are more exposed to risk.
Exploit preconditions
- Attack surface: Publicly reachable Grav Flex Objects pages that render dynamic titles
- Required access: Ability to create or modify page frontmatter, specifically
page.header.flex.collection.titleorpage.header.flex.object.title - Trigger point: Rendering of Flex Objects collection or object views where titles are processed via
template_from_string() - Why exploitation is possible: The plugin passes user-controlled title frontmatter directly to Twig's template engine, bypassing Grav's
Security::cleanDangerousTwig()protections, allowing arbitrary Twig expressions to run server-side
Why this happens
The root cause is a classic server-side template injection pattern mapped to CWE-94: Improper Control of Generation of Code.
The Flex Objects plugin constructs template content from user-controlled frontmatter and feeds it into template_from_string(), causing Twig to interpret the values as executable template code instead of inert text.
Because this path circumvents Grav's dangerous Twig cleaning mechanism, untrusted input is effectively treated as server-side logic, enabling attackers to interact with internal Grav services and ultimately reach command execution primitives.
Potential impact
- An attacker may execute arbitrary Twig code in the Grav application context.
- An attacker could invoke internal Grav services, such as the scheduler, to run system commands.
- An attacker may access or manipulate application data exposed through Twig and Grav services.
- An attacker could escalate from content editor privileges to full compromise of the Grav instance.
General mitigation guidance
Mitigation generally focuses on removing direct evaluation of user-controlled data as templates and tightening trust boundaries around frontmatter.
Common defensive patterns include:
- Treating user-supplied titles and similar metadata as plain text, never as template source.
- Centralizing Twig rendering paths so all evaluations pass through robust sanitization such as dangerous-tag filtering and expression whitelisting.
- Applying strict separation between configuration, content, and executable template constructs, ensuring that content authors cannot introduce logic.
- Enforcing least privilege for application services exposed to templates, limiting what template code can call even if injection occurs.
- Adopting a "safe by default" templating strategy where dynamic behavior is explicit and localized, rather than inferred from untrusted fields.
How teams detect issues like this
Detection can rely on a mix of static analysis, configuration review, and runtime monitoring:
- Static analysis rules that flag calls to
template_from_string()or similar APIs when arguments derive from frontmatter, request parameters, or other user-controlled sources. - Code review practices that specifically look for templating functions accepting untrusted values and verify that proper sanitization or escaping is enforced.
- Policy-based checks in CI that restrict introduction of new dynamic template evaluation paths and require security sign-off for any meta-programming or evaluation features.
- Application logging and monitoring to detect anomalous Twig expressions, unexpected service invocations, or scheduler usage originating from page render paths.

