Summary
Grav contains a stored cross-site scripting vulnerability in audio and video media rendering through the sourceParsedownElement method. When a media URL fragment is inserted into a raw HTML source element without escaping, an attacker who can store or influence the media reference may cause arbitrary HTML or JavaScript to execute in viewers' sessions.
Affected context
The vulnerability may affect Grav deployments that render audio or video media through the vulnerable sourceParsedownElement path. It becomes risky when attacker-controlled or insufficiently trusted media URL fragments are stored and later concatenated into HTML source elements without context-appropriate output encoding. The affected behavior is associated with Grav versions before 2.0.15.
Exploit preconditions
- Attack surface: Grav content or media rendering functionality
- Required access: Ability to submit, edit, or otherwise influence stored media references or URL fragments
- Trigger point: A viewer accesses a page that renders the stored audio or video element
- Why exploitation is possible: The media URL fragment is incorporated into raw HTML without sufficient escaping, allowing markup or script content to be interpreted by the browser
Why this happens
The underlying bug is a failure to apply context-appropriate output encoding when constructing HTML from stored media data. The sourceParsedownElement method concatenates a media URL fragment into a raw source element, allowing data intended as an attribute value to be interpreted as HTML or script content. This behavior maps to CWE-79: Improper Neutralization of Input During Web Page Generation, commonly known as cross-site scripting.
Potential impact
- Arbitrary JavaScript may execute in a viewer's browser session
- Attackers could access data available to the affected user's session
- Page content or media controls could be modified
- Users could be redirected to malicious destinations
- Administrative actions could be performed if a privileged user views the affected content
General mitigation guidance
Mitigation generally focuses on preserving the separation between data and executable markup.
Common defensive patterns include:
- Applying context-aware HTML attribute encoding to media URL values
- Using safe DOM or templating APIs that keep untrusted values as data
- Allowing only approved URL schemes, hosts, and media path formats
- Validating and canonicalizing media references before storage and again before rendering
- Avoiding raw HTML concatenation for user-controlled values
- Limiting content-editing privileges and reducing administrative session permissions
- Applying browser security controls such as an appropriately restrictive Content Security Policy where practical
How teams detect issues like this
Organizations commonly detect this class of issue through:
- Static analysis rules identifying string concatenation into HTML attributes or raw markup
- Code review checks for media rendering paths that omit output encoding
- Tests using harmless markup-like and delimiter characters in stored media fields
- Runtime security testing of pages containing attacker-influenced audio and video elements
- Content policies that restrict who can create or modify rendered media references
- Automated review tools that flag untrusted data flowing into HTML generation APIs

