/

CVE-2026-130735

Severity:

CRITICAL RISK

(9.8)

Twig Injection (CWE-79) in Grav Media Metadata Fields

CVE-2026-130735

Deferred

Vulnerability type

Category:

Twig Injection

CWE:

CWE-79

Impact:

Stored Cross-Site Scripting and Information Disclosure

Severity:

CRITICAL RISK

(9.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

Grav can interpret attacker-controlled image metadata and file names as Twig template syntax when rendering media. A media-only account or anonymous uploader may be able to inject content that runs for page visitors, potentially exposing unpublished content or serving scripts to visitors, including super admins.

Affected context

The issue affects Grav installations using versions from 2.0.0 up to, but not including, 2.2.18. It arises when media metadata—such as image titles, alt text, class or id attributes, or file names—is processed as Twig rather than treated solely as data. The risk depends on whether an attacker can submit or change media and whether the resulting content is rendered in pages.

Exploit preconditions

  • Attack surface: Media upload and the rendering of uploaded media in pages
  • Required access: A media-only account or, where enabled, anonymous upload access
  • Trigger point: A page renders media containing attacker-controlled metadata or a file name
  • Why exploitation is possible: Attacker-supplied Twig delimiters can be interpreted during rendering, allowing injected template content to affect visitors

Why this happens

The underlying bug is that untrusted media fields are treated as template syntax instead of inert data. When user-controlled values reach a Twig evaluation or rendering context without appropriate handling, an attacker may influence the output seen by other users. This is associated with CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').

Potential impact

  • Injected scripts could run in visitors' browsers in the context of the Grav site.
  • Attackers could target privileged visitors, including super admins.
  • Unpublished page content could be exposed.
  • Site content or visitor sessions could be affected, depending on application behavior and browser protections.

General mitigation guidance

Defensive approaches focus on keeping untrusted media data separate from template logic:

  • Treat titles, alt text, attributes, and file names as data; avoid evaluating user-controlled values as templates.
  • Apply context-appropriate output encoding and strict validation when rendering user-supplied fields.
  • Prefer secure-by-default template patterns that do not permit dynamic template evaluation of uploaded content.
  • Limit who can upload media and reduce anonymous upload capabilities where they are not needed.
  • Use least-privilege permissions for accounts that manage media, and consider browser-side defenses such as a restrictive Content Security Policy as an additional layer.

How teams detect issues like this

  • Use static analysis to identify dynamic template evaluation or untrusted values passed into Twig rendering paths.
  • Review media upload and rendering code for user-controlled metadata or file names used in template contexts.
  • Test rendered pages with representative untrusted media fields and verify output remains data rather than executable template content.
  • Enforce policies that prohibit evaluating user-supplied content as templates, and include these checks in code review and CI workflows.

Sources

SourceLink
github.comgithub.com/getgrav/grav/security/advisories/GHSA-jc8q-6vcj-4x25

Frequently asked

questions

A media-only account may be sufficient; anonymous exploitation may be possible where anonymous uploads are enabled.

The injected content is relevant when affected media is rendered in a page. A visitor viewing such a page, including a super admin, may be exposed.

Keep uploaded metadata as data, not template source. Avoid dynamic evaluation of user-controlled values and apply context-appropriate output encoding.

Restrict upload access, review template rendering boundaries, and use static analysis and policy checks to detect untrusted values reaching template evaluation paths.

Find out what's already
exploitable in your codebase.