justhtml has sanitization bypass in custom policies and programmatic DOM

Description

Summary

justhtml 1.17.0 fixes multiple security issues in sanitization, serialization, and programmatic DOM handling.

Most of these issues affected advanced or custom configurations rather than the default safe path.

Affected versions

  • justhtml <= 1.16.0

Fixed version

  • justhtml 1.17.0 released on April 19, 2026

Impact

Custom SVG / MathML sanitization policies

Custom policies that preserved foreign namespaces could allow dangerous content to survive sanitization, including:

  • active HTML integration points such as SVG <foreignObject>, MathML <annotation-xml encoding="text/html">, SVG <title> / <desc>, and MathML text integration points
  • mutation-XSS parser-differential payloads that looked inert in memory but became active HTML after reparse
  • SVG filter="url(...)" attributes that could trigger external fetches

These issues affected:
- JustHTML(..., sanitize=True) with custom foreign-namespace policies
- sanitize() / sanitize_dom()
- low-level terminal Sanitize(...) transform execution

Preserved <style> handling

Constructor-time sanitization and explicit Sanitize(...) transforms did not fully match sanitize() / sanitize_dom() when custom policies preserved <style>.

That could leave resource-loading CSS such as @import or background-image:url(...) in sanitized output from HTML string input.

Programmatic DOM serialization

Programmatic script, style, and Comment(...) nodes could still serialize into active markup in some edge cases.

This could affect applications that build or mutate DOM trees directly before calling to_html() or to_markdown(html_passthrough=True).

Cache mutation and DOM cycle handling

Two lower-severity hardening fixes were included:

  • compiled sanitize-pipeline caches could be mutated after warming and weaken later sanitization
  • parent/child cycles in programmatic DOM trees could cause infinite loops in operations such as to_html() and sanitize_dom()

Default configuration

Most of the issues above did not affect ordinary parsed HTML with the default JustHTML(..., sanitize=True) configuration.

The main risk areas were:

  • custom policies that preserve SVG or MathML
  • custom policies that preserve <style>
  • programmatic DOM construction or mutation
  • low-level direct sanitizer/transform APIs

Recommended action

Upgrade to justhtml 1.17.0.

If users cannot upgrade immediately:

  • avoid preserving SVG or MathML for untrusted input
  • avoid preserving <style> for untrusted input
  • avoid mutating programmatic DOM trees with untrusted script, style, or comment content
  • avoid mutating warmed policy internals or sanitizer caches

Credit

Discovered during an internal security review of justhtml.

Basic information

Type
reviewed
Severity
medium
Advisory on GitHub
Open advisory ↗
Repository advisory
Open repository advisory ↗
Source code
Browse source ↗
Published (advisory)
2026-04-22 21:25:46 UTC
Updated
2026-04-22 21:25:47 UTC
GitHub reviewed
2026-04-22 21:25:46 UTC

CVSS Scores

Base score Version Severity Vector
6.0 4.0
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:H/VA:N/SC:N/SI:L/SA:N Click to expand
Attack vector (AV:N)
Could be attacked over the internet or any normal routed network.
Attack complexity (AC:L)
Exploitation conditions are straightforward and stable.
Attack requirements (AT:P)
Additional preconditions must be present for exploitation.
Privileges required (PR:N)
No privileges are required.
User interaction (UI:P)
A user has to participate (for example click/open/approve).
Vulnerable system confidentiality impact (VC:N)
No confidentiality impact on the vulnerable system.
Vulnerable system integrity impact (VI:H)
High integrity impact on the vulnerable system.
Vulnerable system availability impact (VA:N)
No availability impact on the vulnerable system.
Subsequent system confidentiality impact (SC:N)
No confidentiality impact on subsequent systems.
Subsequent system integrity impact (SI:L)
Limited integrity impact on subsequent systems.
Subsequent system availability impact (SA:N)
No availability impact on subsequent systems.

Identifiers

Type Value
GHSA GHSA-vrx2-77f2-ww34 ↗

CWEs

CWE id Name
CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
CWE-436 Interpretation Conflict
CWE-471 Modification of Assumed-Immutable Data (MAID)
CWE-835 Loop with Unreachable Exit Condition ('Infinite Loop')

Credits

  • EmilStenstrom (coordinator)

Affected packages (1)

Vulnerable version ranges and first patched releases as published by GitHub.

Ecosystem Package Vulnerable range First patched Vulnerable functions
pip justhtml < 1.17.0 1.17.0

References

cvelogic Threat Intelligence