/

CVE-2026-42612

Severity:

HIGH RISK

(8.5)

XSS in Grav detectXss() HTML Event Attribute Filtering

CVE-2026-42612

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79

Impact:

Stored client-side code execution in users' browsers

Severity:

HIGH RISK

(8.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.

Sources

SourceLink
github.comgithub.com/getgrav/grav/commit/5a12f9be8314682c8713e569e330f11805d0a663
github.comgithub.com/getgrav/grav/security/advisories/GHSA-9695-8fr9-hw5q

Frequently asked

questions

Exploitation is limited to users with publisher-level (or similar) permissions who can author or edit content, but once a malicious payload is stored, it can affect any visitor who views the compromised page, including administrators.

No server-level access is required; a valid publisher-level account with the ability to inject or edit content that is rendered as HTML is sufficient to exploit the issue.

Replace ad-hoc blacklist-based XSS checks with well-tested, whitelist-based sanitization and context-aware output encoding, and avoid allowing inline event handlers or raw HTML in user-controlled content wherever possible.

Standardize on trusted sanitization and encoding libraries, enforce secure coding guidelines that prohibit manual regex-based XSS filters, restrict powerful content-editing roles, and include XSS-focused tests and automated security scans in the development pipeline.

Find out what's already
exploitable in your codebase.