CVE-2026-58657: Grav Stored CSS Injection Vulnerability
MODERATECVE-2026-58657 is a MODERATE (CVSS 4.8) stored css injection vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Grav libraries in the Packagist ecosystem. The issue involves stored css injection via markdown image resize() bypasses prior media style sanitizers in grav. Remediation is available by upgrading affected packages to version 2.0.0.
CVE-2026-58657 at a Glance
Security Impact
CVSS: 4.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:L/I:L/A:N).
How to Fix CVE-2026-58657
To remediate this vulnerability, upgrade all affected Grav dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade getgrav/grav to 2.0.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for getgrav/grav
How to Check if You Are Affected
To determine whether your application is affected by CVE-2026-58657, inspect your project dependencies for Grav:
inspect dependencies for getgrav/grav
Analyze the terminal output to locate any version of Grav in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.0), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Grav, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-58657 Affected Grav Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
getgrav/grav
|
Packagist |
≥ 2.0.0-rc.9
< 2.0.0
All 1 versions
2.0.0-rc.9
|
2.0.0
|
References
Frequently Asked Questions
What is CVE-2026-58657?
Which Grav versions are affected?
What version fixes CVE-2026-58657?
Is getgrav/grav affected?
What is the CVSS score of CVE-2026-58657?
What CWE is associated with CVE-2026-58657?
How can I check Packagist dependencies for CVE-2026-58657?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-ffmg-hfvg-jhg9",
"modified" : "2026-09-16T22:14:53Z",
"published" : "2026-09-16T22:14:53Z",
"aliases" : [ "CVE-2026-58657" ],
"summary" : "Grav: Stored CSS injection via Markdown image resize() bypasses prior media style sanitizers in Grav",
"details" : "## Summary\n\nGrav 2.0.0-rc.9 and the current 2.0 branch still allow stored CSS injection through Markdown image media actions. The prior media hardening rejects direct `?style=` payloads and unsafe `attribute()` fallbacks, but the adjacent `resize()` action still writes caller-controlled values directly into `styleAttributes`.\n\nA publisher who can edit page Markdown can store a crafted image URL that renders additional CSS declarations in the final `<img style=...>` attribute. This crosses the same lower-privileged publisher to higher-privileged reviewer/admin rendered-content boundary as the earlier media style and attribute advisories.\n\n## Impact\n\nA lower-privileged content editor can persist CSS declarations that are rendered when a higher-privileged user views the page or admin preview. The demonstrated payload creates a full-viewport fixed overlay by injecting `position:fixed`, viewport dimensions, background color, and z-index declarations.\n\nThis does not require JavaScript execution. The impact is stored CSS injection in rendered content, with UI redress/overlay and content-manipulation risk in higher-privileged sessions.\n\n## Reproduction\n\nTested versions:\n\n- Grav 2.0 branch commit `6582166173bb8eb5869d96aea384e0e73777c94c`\n- Grav `2.0.0-rc.9` commit `e03d29aa0d3ece16d73c1ffccfa78df8bf5f28b8`\n\nMinimal Markdown payload:\n\n```markdown\n\n```\n\nA minimal PHPUnit-style reproducer can drive the same parser path directly:\n\n```php\n$m = new class {\n use \\Grav\\Common\\Media\\Traits\\MediaObjectTrait;\n use \\Grav\\Common\\Media\\Traits\\StaticResizeTrait;\n\n public function addMetaFile($filepath) {}\n public function __toString(): string { return ''; }\n public function url($reset = true) { return '/img.png'; }\n public function get($name, mixed $default = null, $separator = null) { return $default; }\n public function set($name, mixed $value, $separator = null) { return $this; }\n protected function createThumbnail($thumb) { return null; }\n protected function createLink(array $attributes) { return null; }\n protected function getItems(): array { return []; }\n};\n\n$excerpts = new \\Grav\\Common\\Page\\Markdown\\Excerpts(null, ['markdown' => [], 'images' => []]);\n$m = $excerpts->processMediaActions(\n $m,\n 'image.png?resize=100;position:fixed;top:0;left:0;width:100vw;height:100vh;background:white;z-index:9999,200'\n);\n$element = $m->parsedownElement('', '', '', '', false);\nvar_dump($element['attributes']['style']);\n```\n\nObserved style attribute:\n\n```text\nwidth: 100;position:fixed;top:0;left:0;width:100vw;height:100vh;background:white;z-index:9999px;height: 200px;\n```\n\nThe appended `px` lands on the final `z-index` value, but the preceding injected declarations remain syntactically valid CSS.\n\n## Root Cause / Technical Details\n\n`system/src/Grav/Common/Page/Markdown/Excerpts.php::processMediaActions()` parses the image query string into media actions and invokes the requested public media method with `call_user_func_array([$medium, $action['method']], $args)`.\n\nFor `resize()`, `system/src/Grav/Common/Media/Traits/StaticResizeTrait.php::resize()` stores width and height directly into style attributes:\n\n```php\n$this->styleAttributes['width'] = $width . 'px';\n$this->styleAttributes['height'] = $height . 'px';\n```\n\nIt does not verify that the values are numeric, length-only, or free of CSS declaration delimiters. Later, `system/src/Grav/Common/Media/Traits/MediaObjectTrait.php::parsedownElement()` serializes keyed style attributes as raw CSS declarations:\n\n```php\n$style .= $key . ': ' . $value . ';';\n```\n\nThe sanitizer added for direct `style()` inputs is not reached for values introduced by `resize()`. As a result, `resize=100;position:fixed;...,200` breaks out of the intended `width:` value and injects additional declarations.\n\n## PoC Evidence\n\nOn both current 2.0 and 2.0.0-rc.9, the targeted regression test produced the injected style string above. Existing tests still confirm the direct `style()` and `attribute()` paths are rejected; the bypass is specific to the adjacent `resize()` styleAttributes path.\n\n## Remediation\n\nSanitize or type-normalize all values before they enter `styleAttributes`, not only values passed through `MediaObjectTrait::style()`. For `resize()`, cast or validate width and height as numeric values before appending `px`, or use a shared CSS declaration builder that rejects semicolons, colons, property names, and other declaration-breaking characters. Add regression coverage for `resize=100;position:fixed;top:0,200` and any other media action that writes to `styleAttributes` directly.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:L/I:L/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "Packagist",
"name" : "getgrav/grav"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "2.0.0-rc.9"
}, {
"fixed" : "2.0.0"
} ]
} ],
"versions" : [ "2.0.0-rc.9" ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/getgrav/grav/security/advisories/GHSA-ffmg-hfvg-jhg9"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-58657"
}, {
"type" : "WEB",
"url" : "https://github.com/getgrav/grav/commit/6582166173bb8eb5869d96aea384e0e73777c94c"
}, {
"type" : "WEB",
"url" : "https://github.com/getgrav/grav/commit/e03d29aa0d3ece16d73c1ffccfa78df8bf5f28b8"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/getgrav/grav"
}, {
"type" : "WEB",
"url" : "https://www.vulncheck.com/advisories/grav-stored-css-injection-via-markdown-image-resize-action"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-09-16T22:14:53Z",
"nvd_published_at" : null
}
}