Skip to main content
Vulnerability Database/CVE-2026-61784

CVE-2026-61784: xhtml-purifier XSS Vulnerability

CVE-2026-61784 is a cross-site scripting flaw in xhtml-purifier that allows attackers to inject malicious JavaScript by breaking out of HTML attributes. This post explains its impact, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-61784 Overview

CVE-2026-61784 is a sanitizer bypass in xhtml-purifier, a Node.js library that cleans untrusted HTML input. Versions prior to 0.4.3 fail to HTML-entity-encode attribute values during serialization. An attacker-controlled value in any allowed attribute (class, style, title, alt, src, href) can include a double-quote character to break out of the attribute context. The injected payload can introduce a JavaScript event handler such as onmouseover or onerror that survives sanitization and executes when the output is rendered. This cross-site scripting (XSS) weakness is tracked under [CWE-79].

Critical Impact

Attackers can inject executable JavaScript event handlers through any permitted HTML attribute, defeating the purifier and achieving stored or reflected XSS in applications relying on xhtml-purifier for output sanitization.

Affected Products

  • xhtml-purifier Node.js library versions prior to 0.4.3
  • Applications embedding xhtml-purifier to sanitize user-supplied HTML
  • Downstream Node.js services rendering purified output in browser contexts

Discovery Timeline

  • 2026-09-24 - CVE-2026-61784 published to NVD
  • 2026-09-30 - Last updated in NVD database

Technical Details for CVE-2026-61784

Vulnerability Analysis

The flaw resides in the attributeString() function within XHTMLPurifier.js (around line 148). The function concatenates attribute values directly into a double-quoted attribute string without encoding reserved HTML characters. When the input value contains a double-quote ("), the serializer closes the current attribute early and treats subsequent characters as new attribute tokens. This allows an attacker to append arbitrary attributes, including event handlers that execute JavaScript when the rendered element loads or receives user interaction. Because the attack occurs during output serialization, prior sanitization checks on allowed tags and attributes do not prevent the bypass.

Root Cause

The root cause is missing output encoding in attribute serialization. The affected code path (string += " " + name + "=\"" + value + "\"") assumes attribute values are safe once the attribute name passes allow-list validation. It does not escape ", <, >, or &, violating contextual output encoding requirements for HTML attribute contexts.

Attack Vector

An attacker submits HTML containing an allowed element with a crafted attribute value such as title="x" onmouseover="alert(1)" x=". The purifier accepts the base attribute, then emits the raw value during serialization, producing output that includes the attacker's injected onmouseover handler. Exploitation requires user interaction (UI:R) with the rendered page, consistent with reflected or stored XSS workflows.

javascript
// Patch from XHTMLPurifier.js — encodes attribute values before serialization
// SECURITY: HTML-entity-encode the attribute value so a value
// containing a double-quote (or angle brackets) cannot break out
// of the quoted attribute and inject additional attributes/handlers.
var encodedValue = String(value)
    .replace(/&(?![a-zA-Z][a-zA-Z0-9]*;|#\d+;|#x[0-9a-fA-F]+;)/g, "&")
    .replace(/"/g, """)
    .replace(/</g, "<")
    .replace(/>/g, ">");

string += " " + name + "=\"" + encodedValue + "\"";

Source: GitHub commit 21d461a

Detection Methods for CVE-2026-61784

Indicators of Compromise

  • HTML output containing unexpected event handler attributes (onmouseover, onerror, onclick, onload) after passing through xhtml-purifier
  • Stored content in databases where attribute values contain literal " characters followed by additional attribute tokens
  • Browser Content Security Policy (CSP) violation reports referencing inline script execution from user-generated content

Detection Strategies

  • Inventory Node.js dependencies with npm ls xhtml-purifier and flag any version below 0.4.3
  • Scan stored HTML content for attribute values containing " followed by whitespace and known event handler names
  • Deploy a strict CSP that blocks inline event handlers and monitor violation reports for sanitizer failures

Monitoring Recommendations

  • Log and alert on web application firewall (WAF) matches for XSS payloads targeting user-submitted HTML endpoints
  • Monitor outbound requests from browsers rendering sanitized content for unexpected script-initiated connections
  • Instrument server-side logging around calls to xhtml-purifier to capture inputs that trigger abnormal output sizes

How to Mitigate CVE-2026-61784

Immediate Actions Required

  • Upgrade xhtml-purifier to version 0.4.3 or later across all Node.js services
  • Audit stored user-generated HTML for pre-existing attribute-injection payloads and re-sanitize with the patched version
  • Enforce a Content Security Policy that disallows inline event handlers and inline scripts

Patch Information

The maintainers fixed the issue in xhtml-purifier version 0.4.3. The patch, available in GitHub commit 21d461a, introduces HTML-entity encoding for &, ", <, and > in attributeString() before concatenation. See the full advisory at GHSA-j8r4-32c5-33rc.

Workarounds

  • Replace xhtml-purifier with an actively maintained sanitizer such as DOMPurify if upgrading is not immediately feasible
  • Pre-filter input to reject or strip double-quote characters from attribute candidates before sanitization
  • Apply a strict CSP (for example, default-src 'self'; script-src 'self') to block execution of injected inline handlers
bash
# Upgrade the vulnerable package to the fixed release
npm install xhtml-purifier@0.4.3 --save

# Verify installed version
npm ls xhtml-purifier

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.