Severity:

CRITICAL RISK

(9.8)

HTML Sanitization Bypass (CWE-20) in justhtml Library

CVE-2026-7808

Deferred

Vulnerability type

Category:

HTML Sanitization Bypass

CWE:

CWE-20

Impact:

Potential Cross-Site Scripting

Severity:

CRITICAL RISK

(9.8)

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

Multiple sanitization bypass conditions in justhtml before 1.16.0 may allow dangerous HTML, SVG, MathML, script, or style content to survive filtering. The risk is greatest when applications mutate or reuse policy objects, sanitize programmatically constructed DOM trees, or enable custom foreign-content policies, potentially resulting in cross-site scripting.

Affected context

The issue can occur in advanced justhtml usage rather than the ordinary JustHTML(..., sanitize=True) path for typical parsed HTML. Relevant conditions include reusable or mutable sanitization policies, programmatic DOM input, mixed-case element names, crafted doctype values, and custom policies that preserve SVG or MathML content. Applications that render sanitized output in a browser-facing context may be exposed when active content is not removed.

Exploit preconditions

  • Attack surface: Application code that uses justhtml sanitization or DOM serialization.
  • Required access: The ability to supply or influence HTML, DOM nodes, policy objects, or related document metadata processed by the application.
  • Trigger point: Sanitization or serialization of crafted programmatic input, reused policy state, foreign-content elements, or namespace metadata.
  • Why exploitation is possible: Validation and foreign-content checks may rely on incomplete normalization or mutable policy state, allowing dangerous content to remain in output that is later interpreted by a browser.

Why this happens

The underlying bug class is improper input validation, mapped to CWE-20. Sanitization decisions can be bypassed when element names are not normalized consistently, when policy objects retain unsafe mutations across calls, or when namespace, doctype, SVG, and MathML handling does not accurately represent the resulting markup. These patterns weaken the boundary between inert document data and browser-interpreted active content.

Potential impact

  • A browser may execute attacker-controlled script content.
  • An attacker could access data available to the affected web origin.
  • User sessions or application actions could be exposed to unauthorized manipulation.
  • Malicious style, animation, or external resource references could affect rendered content.
  • Applications could experience content spoofing or persistent client-side compromise.

General mitigation guidance

Mitigation generally focuses on making sanitization deterministic, strictly normalized,

and resistant to policy-state changes.

Common defensive patterns include:

  • Using a maintained sanitization implementation with safe-by-default behavior.
  • Treating sanitization policies as immutable, isolated configuration rather than shared mutable state.
  • Normalizing tag names, attributes, namespaces, and document metadata before applying security decisions.
  • Applying conservative allowlists for SVG, MathML, animation elements, style attributes, and external references.
  • Validating programmatic DOM objects as strictly as parsed source HTML.
  • Encoding or otherwise safely handling sanitized output according to its browser rendering context.
  • Limiting the privileges and origin capabilities of applications that process untrusted markup.

How teams detect issues like this

Organizations can look for this class of issue through:

  • Static analysis rules identifying shared or mutable sanitizer policy objects.
  • Code review checks for separate handling of parsed HTML and programmatic DOM input.
  • Tests using mixed-case element names, crafted doctypes, namespace mismatches, SVG and MathML animation elements, and external url(...) references.
  • Regression tests that verify dangerous content is absent after repeated sanitization calls.
  • Policy enforcement that requires explicit, reviewed allowlists for foreign-content namespaces and active attributes.
  • Automated security review tools that flag browser-facing HTML sanitization and serialization paths.

Sources

SourceLink
github.comgithub.com/EmilStenstrom/justhtml/security/advisories/GHSA-4p64-v8f5-r2gx
vulncheck.comvulncheck.com/advisories/justhtml-before-multiple-security-issues-via-sanitization

Frequently asked

questions

It can be, when an application accepts attacker-influenced markup or DOM data

and returns the sanitized result to a browser. Exploitability depends on the

application's input sources, rendering context, and sanitization configuration.

The described conditions primarily affect advanced usage. Ordinary parsed HTML

processed through the default sanitization path may not encounter the same

bypasses, but applications should not assume safety without testing their

specific configuration and input flow.

Use safe-by-default sanitization with immutable, isolated policies; normalize

names and namespaces consistently; and apply conservative allowlists to SVG,

MathML, style, animation, and external-reference features.

Maintain regression tests for mixed-case tags, programmatic DOM trees, crafted

doctypes, repeated policy use, and foreign-content edge cases. Also ensure that

sanitized output is safely encoded and rendered according to its context.

Find out what's already
exploitable in your codebase.