/

CVE-2026-58655

Severity:

HIGH RISK

(8.8)

Server-side Twig Injection (CWE-94) in Grav Flex Objects

CVE-2026-58655

Deferred

Vulnerability type

Category:

Server-Side Template Injection

CWE:

CWE-94

Impact:

Remote Code Execution via Arbitrary Twig Evaluation

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.title or page.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.

Sources

SourceLink
github.comgithub.com/getgrav/grav/security/advisories/GHSA-623v-m3c4-3pw8
vulncheck.comvulncheck.com/advisories/grav-flex-objects-server-side-template-injection-via-dynamic-titles

Frequently asked

questions

Exploitability depends on who can control the relevant frontmatter fields. If content editors or external users can modify Flex Objects titles on publicly reachable pages, the issue is broadly exploitable; locked-down sites with tightly controlled frontmatter have a narrower attack surface.

An attacker needs the ability to create or modify the page.header.flex.collection.title or page.header.flex.object.title frontmatter values for a page that is rendered by the Flex Objects plugin. This typically corresponds to content editing or page creation rights.

The safest pattern is to ensure that user-controlled data is never treated as template source. Instead, all such values should be handled as plain text, escaped appropriately, and rendered through predefined templates that do not depend on dynamic evaluation of content-supplied logic.

Prevention involves establishing strict guidelines around templating: avoid dynamic evaluation APIs for untrusted inputs, enforce centralized sanitization and escaping, use static templates where possible, and include template engine usage in regular security reviews and automated checks.

Find out what's already
exploitable in your codebase.