Summary
Grav, a file-based web platform, contained a stored Cross-Site Scripting (XSS) vulnerability that allowed publisher-level accounts to persist arbitrary JavaScript in site content.
The flaw stems from a blacklist bypass in the detectXss() function when processing unquoted HTML event attributes, enabling malicious scripts to execute in visitors' browsers whenever the affected content is rendered.
Affected context
The vulnerability occurs in Grav installations where publisher-level users can create or edit content that is later rendered as HTML to site visitors.
It specifically affects environments relying on Grav's detectXss() function for sanitizing user-supplied markup, especially where HTML event attributes (such as onclick, onmouseover, etc.) are allowed or partially filtered.
The issue manifests when the filter attempts to block dangerous patterns using a blacklist but fails to correctly handle unquoted HTML event attribute values, leaving a path for malicious JavaScript to be injected and stored.
Exploit preconditions
- Attack surface: Web-based content editing interfaces or any feature where publisher-level users can input HTML or rich text rendered as part of pages.
- Required access: A valid publisher-level account (or equivalent role) with permission to create or modify content or templates that are displayed to other users.
- Trigger point: Viewing of the affected page or content by any user in a browser; the malicious payload executes when the stored content is rendered and the browser processes the crafted event attribute.
- Why exploitation is possible: The detectXss() function relies on blacklist-style checks and does not correctly account for unquoted HTML event attribute values, allowing attackers to craft inputs that evade the filter and embed executable JavaScript.
Why this happens
This vulnerability is rooted in CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
The detectXss() function attempts to identify and block dangerous markup using a blacklist-based approach, matching on specific patterns that are assumed to be malicious.
However, HTML and JavaScript contexts are complex and flexible, and the function fails to robustly handle the case where event handler attributes (e.g., onclick) are supplied without quotes around their values.
Because the sanitization logic does not fully model browser parsing rules, an attacker can construct payloads that avoid blacklist patterns while still being interpreted by the browser as executable script, resulting in stored script injection whenever the content is loaded.
Potential impact
- Execution of arbitrary JavaScript in the context of the affected Grav site when visitors view the compromised content.
- Theft or modification of session data stored in the browser, subject to cookie flags and browser protections.
- Unauthorized actions performed on behalf of logged-in users via forged requests (e.g., changing settings, posting content), within the limits of their account privileges.
- Injection of malicious UI elements (phishing overlays, fake login prompts) to harvest credentials or sensitive information from visitors.
- Manipulation of displayed content to mislead users or damage the integrity and reputation of the site.
General mitigation guidance
Effective mitigation focuses on context-aware output encoding and robust HTML sanitization rather than blacklisting specific patterns.
Recommended defensive patterns include:
- Favor a whitelist-based HTML sanitizer that only permits a minimal, explicitly defined set of tags and attributes and strips or encodes everything else.
- Apply context-sensitive output encoding for all user-controlled content before it is embedded into HTML, attribute, JavaScript, or URL contexts.
- Avoid relying on blacklist pattern checks for XSS; instead, use well-maintained libraries that accurately model browser parsing rules.
- Restrict or entirely disallow inline event handler attributes (e.g.,
onclick) in user-supplied content, preferring unobtrusive JavaScript bound via code controlled by the application. - Enforce the principle of least privilege for roles such as publishers, limiting where raw HTML is allowed and separating content editing capabilities from template or layout editing.
- Consider deploying browser-level mitigations such as a strict Content Security Policy (CSP) that disallows inline scripts and restricts script sources to controlled origins.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis and code review:
- Flag custom XSS detection or sanitization functions that rely on regex or blacklist-style checks against HTML or JavaScript content.
- Identify direct insertion of user-controlled data into HTML without passing through a vetted encoding/sanitization layer.
- Review role-based content editing features where rich HTML or Markdown with embedded HTML is allowed, ensuring proper encoding and sanitization layers exist.
- Automated security testing:
- Use dynamic application security testing (DAST) tools configured to probe for stored XSS by injecting payloads into content fields and later revisiting pages where that content is rendered.
- Incorporate unit and integration tests that validate the behavior of sanitization utilities (e.g., detectXss()) against a corpus of known XSS payload variants, including unquoted attributes.
- Operational monitoring:
- Monitor logs and client-side error tracking for anomalous JavaScript errors or execution patterns originating from stored content areas.
- Use Content Security Policy violation reports (if CSP is deployed) to detect unexpected inline script or event handler executions.

