Junglewise Threat Intelligence

CVE-2026-5389: justhtml to_markdown() cross-site scripting via code fence breakout

CVE-2026-5389 · Severity: medium · CVSS 6.1 · Published 2026-08-23

Technologies: EmilStenstrom Justhtml.

Executive brief

justhtml is a Python library for sanitizing and converting HTML to Markdown. A flaw in the to_markdown() function allows attackers to inject backticks inside code blocks, breaking out of fixed-length fences and exposing raw HTML to downstream Markdown renderers. When the resulting Markdown is rendered, the attacker-controlled HTML can execute, leading to cross-site scripting attacks in applications that treat the output as safe.

Technical details

The vulnerability is a cross-site scripting (XSS) bypass in the to_markdown() function's handling of HTML <pre> elements (CWE-80). When converting <pre> content to Markdown, the serializer wraps decoded text in fixed triple-backtick code fences (```) without checking if the content contains backtick sequences that could break the fence. An attacker can inject backtick runs (``` or longer) within sanitized <pre> elements to prematurely close the code block, allowing subsequent HTML-like text to appear outside the fence where it is treated as raw HTML by CommonMark/GFM renderers. No authentication is required; the attack is network-reachable and requires only user interaction (rendering the Markdown output). The vulnerability affects justhtml versions before 1.13.0, which patches the issue by dynamically selecting a fence length longer than the longest backtick run in the content.

Affected products

  • EmilStenstrom justhtml before 1.13.0

Timeline

  • 2026-03-21: disclosed
  • 2026-03-21: patched: Version 1.13.0 released
  • 2026-08-23: advisory: CVE-2026-5389 published

References