Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2026-86197

CVE-2026-86197: Grav CMS XSS Vulnerability in Twig Sandbox

CVE-2026-86197 is a cross-site scripting vulnerability in Grav CMS that allows page editors to inject malicious scripts through the Twig sandbox policy. This article covers the technical details, affected versions, and mitigation strategies.

Published:

CVE-2026-86197 Overview

CVE-2026-86197 is a stored cross-site scripting [CWE-79] vulnerability in Grav flat-file content management system (CMS) versions prior to 2.0.20. The flaw resides in the Twig sandbox policy, which allowlists the addJs and addCss methods on the Grav\Common\Assets class without enforcing output escaping. Page editors can register malicious assets or inject attributes that render unescaped into <head> tags. The injected script executes in the browser context of every site visitor, including administrators. Exploitation requires authenticated editor-level access and user interaction from a victim loading an affected page.

Critical Impact

Authenticated page editors can inject persistent JavaScript into document head tags, executing arbitrary script in the browser context of all visitors, including administrators.

Affected Products

  • Grav CMS versions prior to 2.0.20
  • Grav Twig sandbox policy component
  • Grav\Common\Assets class methods addJs and addCss

Discovery Timeline

  • 2026-09-05 - CVE-2026-86197 published to the National Vulnerability Database (NVD)
  • 2026-09-10 - Last updated in NVD database

Technical Details for CVE-2026-86197

Vulnerability Analysis

Grav uses a Twig sandbox policy to constrain what page authors can invoke from within templates. The sandbox explicitly allowlists the addJs and addCss methods on Grav\Common\Assets. These methods accept asset URLs and additional attribute arrays that Grav emits verbatim into <script> and <link> tags rendered inside the document head.

Because the sandbox trusts these methods, editor-supplied input passes through without HTML entity encoding or attribute escaping. An attacker with page-editing privileges registers an asset whose URL or attributes contain script payloads or attribute-breaking characters. Grav then renders the payload into every page that includes the compromised template.

The stored payload runs whenever a visitor loads the affected page. When an administrator opens the page, the script executes with administrator session context, enabling session token theft, privileged API calls, or account takeover chains.

Root Cause

The root cause is an incomplete sandbox policy. The allowlist grants access to asset-registration methods without wrapping their output in escaping filters. Grav treats sandbox membership as sufficient authorization, so no downstream sanitization runs on asset URLs or attribute values before they reach the rendered HTML.

Attack Vector

Exploitation requires an authenticated account with permission to edit page content or Twig templates. The attacker crafts a Twig expression that calls addJs or addCss with a payload injected into the URL or attribute parameters. On rendering, the malicious markup appears inside the document head and executes for every visitor. See the GitHub Security Advisory GHSA-8hgv-xc77-jmcr and the VulnCheck Advisory: Grav XSS Vulnerability for technical details.

No public proof-of-concept exploit code is referenced in the advisories at the time of publication.

Detection Methods for CVE-2026-86197

Indicators of Compromise

  • Unexpected <script> or <link> tags in rendered page head sections referencing external or javascript: URLs
  • Page or template revisions containing Twig calls to addJs or addCss with attributes carrying angle brackets, quotes, or event handlers such as onload
  • New or modified content files under the Grav user/pages/ directory with unusual asset registrations
  • Administrator sessions initiating unexpected API calls to Grav admin endpoints shortly after loading editor-authored pages

Detection Strategies

  • Audit Grav page and template revision history for Twig expressions invoking addJs or addCss with untrusted parameters
  • Deploy Content Security Policy (CSP) reporting to surface script executions from unexpected origins
  • Review web server access logs for anomalous outbound requests originating from administrator browsers
  • Compare deployed page assets against known-good baselines to identify unauthorized asset injection

Monitoring Recommendations

  • Alert on modifications to files under user/pages/ and user/themes/ made by non-administrator accounts
  • Forward Grav admin authentication and content-change events to a centralized logging platform for correlation
  • Monitor CSP violation reports for inline or third-party script execution attempts
  • Track editor accounts that suddenly begin registering external JavaScript or CSS assets

How to Mitigate CVE-2026-86197

Immediate Actions Required

  • Upgrade Grav to version 2.0.20 or later on all instances
  • Review all page editor and contributor accounts, revoking access for unnecessary users
  • Inspect existing pages and templates for malicious addJs or addCss calls and remove offending content
  • Rotate administrator session tokens and passwords if compromise is suspected

Patch Information

Grav 2.0.20 addresses the vulnerability by tightening the Twig sandbox policy so asset-registration methods no longer emit unescaped attacker-controlled values. Refer to the GitHub Security Advisory GHSA-8hgv-xc77-jmcr for the fix details and upgrade guidance.

Workarounds

  • Restrict page-editing and template-editing permissions to fully trusted accounts until the patch is applied
  • Deploy a strict Content Security Policy that blocks inline scripts and restricts script sources to a known allowlist
  • Place a web application firewall (WAF) rule in front of Grav to inspect submitted page content for addJs and addCss calls containing suspicious attribute payloads
  • Disable the Grav admin plugin on production hosts when active content editing is not required
bash
# Upgrade Grav using the built-in CLI updater
bin/gpm selfupgrade -f
bin/gpm update

# Verify the installed version is 2.0.20 or later
bin/grav --version

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.