getgrav/grav
Affected
- introduced
0, fixed2.0.0-beta.2(ecosystem)
Fixed versions
2.0.0-beta.2
Fix
The export has no generic command for this ecosystem.
Advisory
Also known as: CVE-2026-42841
Grav CMS vulnerable to stored XSS via Markdown media attribute() action
Summary
An authenticated user with page editing permissions can inject an executable JavaScript event-handler attribute into rendered image HTML through Grav's Markdown media action syntax.
The issue is caused by Markdown image query parameters being converted into callable media actions. The public attribute() media method can be reached this way, allowing an editor to set an arbitrary HTML attribute name and value on the generated image element.
For example, this Markdown:
)
is rendered as an image tag containing an executable onload handler:
<img onload="alert(document.domain)" alt="Quarterly market overview" src="/user/pages/03.campaigns/market-overview.gif?...">
This results in stored XSS when another user views the affected page. In a multi-user Grav installation, a lower-privileged page editor could use this to target administrators or reviewers who preview or view editor-controlled content.
Tested versions:
Suggested classification:
CVSS:4.0/AV:N/AC:L/AT:P/PR:H/UI:P/VC:H/VI:L/VA:N/SC:H/SI:L/SA:NCVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:H/I:L/A:NDetails
The issue appears to come from this source-to-sink flow:
ParsedownGravTrait::inlineImage() processes Markdown images.Excerpts::processImageExcerpt() resolves the referenced media object.Excerpts::processMediaActions() parses the image URL query string into media actions.call_user_func_array() invokes the requested action method on the media object.MediaObjectTrait::attribute() stores the attacker-controlled attribute name and value.Relevant code paths:
system/src/Grav/Common/Markdown/ParsedownGravTrait.php
system/src/Grav/Common/Page/Markdown/Excerpts.php
system/src/Grav/Common/Media/Traits/MediaObjectTrait.php
system/src/Grav/Common/Page/Medium/StaticImageMedium.php
system/src/Grav/Common/Page/Medium/ImageMedium.php
vendor/erusev/parsedown/Parsedown.php
In system/src/Grav/Common/Markdown/ParsedownGravTrait.php, Markdown image excerpts are passed into Grav-specific media handling:
if (isset($excerpt['element']['attributes']['src'])) {
$excerpt = $this->excerpts->processImageExcerpt($excerpt);
}
In system/src/Grav/Common/Page/Markdown/Excerpts.php, query string parameters are converted into media action calls. The query parameter name becomes the method name:
$carry[] = ['method' => $parts[0], 'params' => $value];
The requested method is later invoked dynamically:
$medium = call_user_func_array([$medium, $action['method']], $args);
For the payload:
attribute=onload,alert(document.domain)
the method is attribute, and the arguments are onload and alert(document.domain).
In system/src/Grav/Common/Media/Traits/MediaObjectTrait.php, attribute() stores the caller-controlled attribute name directly:
public function attribute($attribute = null, $value = '')
{
if (!empty($attribute)) {
$this->attributes[$attribute] = $value;
}
return $this;
}
The image media classes then return the collected attributes as attributes for an img element.
In system/src/Grav/Common/Page/Medium/StaticImageMedium.php:
return ['name' => 'img', 'attributes' => $attributes];
The non-static image path in system/src/Grav/Common/Page/Medium/ImageMedium.php also returns image attributes in the same way.
Finally, in vendor/erusev/parsedown/Parsedown.php, the attribute value is escaped, but the attribute name is rendered as-is:
$markup .= ' '.$name.'="'.self::escape($value).'"';
As a result, the attacker-controlled attribute name onload is emitted into the final HTML and executes as a browser event handler.
The Admin Plugin's save-time XSS detection does not appear to block this because the stored content is Markdown media syntax, not raw HTML:
)
The dangerous HTML is generated later during Markdown/media rendering.
PoC
I reproduced this on a standard Grav CMS installation with the Admin Plugin enabled.
Configuration and prerequisites:
market-overview.gifSteps to reproduce:
market-overview.gif. )
onload attribute.Expected result:
The Markdown media action should not be able to generate executable HTML attributes. The payload should be rejected, sanitized, or rendered without the dangerous event-handler attribute.
Actual result:
The payload is accepted and rendered as an executable image event handler:
<img onload="alert(document.domain)" alt="Quarterly market overview" src="/user/pages/03.campaigns/market-overview.gif?...">
Screenshots:
<img width="1718" height="1013" alt="edycja" src="https://github.com/user-attachments/assets/8f5e5275-e4ef-4d5e-a2cd-44683537b909" />
<img width="1727" height="1002" alt="alert" src="https://github.com/user-attachments/assets/6de81228-830c-49f2-ac41-b15658a8913d" />
onload attribute in the rendered DOM<img width="939" height="539" alt="inspect" src="https://github.com/user-attachments/assets/7832c42d-6f3a-4ea2-b072-b837bd3913ed" />
Impact
This is a stored cross-site scripting vulnerability.
An authenticated user with page editing permissions can store a malicious Markdown image reference. When the affected page is rendered, the payload executes in the browser of any user who views that page.
In multi-user Grav installations, this may allow a lower-privileged editor to target administrators, reviewers, or other privileged users who preview or view editor-controlled content. Depending on the victim's privileges and deployed plugins, successful exploitation may allow JavaScript execution in the site origin, access to same-origin page data available to the victim, and same-origin actions performed as the victim.
Medium Basis: The source's own band: MODERATE
0, fixed 2.0.0-beta.2 (ecosystem)2.0.0-beta.2
The export has no generic command for this ecosystem.
Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0