Summary
justhtml can preserve HTML-significant angle brackets when converting parsed text nodes to Markdown with to_markdown(). If untrusted content is rendered as HTML after conversion, this may bypass sanitization and enable cross-site scripting, particularly when text was entity-decoded or parsed from special HTML elements.
Affected context
The vulnerability occurs in applications that use justhtml to convert untrusted HTML or parsed document content into Markdown and subsequently render that Markdown in a browser or HTML-capable interface. It is most relevant when the conversion output is treated as sanitized content, while angle brackets from text nodes remain available for interpretation as raw HTML.
Exploit preconditions
- Attack surface: The
to_markdown()document-to-Markdown conversion path - Required access: Ability to supply or influence HTML, text-node, or document content processed by the application
- Trigger point: Rendering the generated Markdown in a context that permits embedded HTML
- Why exploitation is possible: HTML-significant characters such as
<and>may remain unescaped, allowing content that appeared safe before conversion to be interpreted as markup after rendering
Why this happens
The underlying bug is incomplete output encoding during Markdown serialization. Although some Markdown metacharacters are escaped, angle brackets in text nodes are not consistently encoded as data, so entity-decoded text or content parsed from RCDATA and RAWTEXT-related elements can become raw HTML in the output. This maps to CWE-79: Improper Neutralization of Input During Web Page Generation, because attacker-controlled content can cross a trust boundary without adequate context-appropriate escaping.
Potential impact
- An attacker could execute script in the security context of a vulnerable application
- Users may be exposed to session theft, phishing content, or unauthorized actions
- Sanitization controls could be bypassed when they trust Markdown conversion as a safety boundary
- Rendered content could be altered to distribute malicious links or misleading interface elements
General mitigation guidance
Mitigation generally focuses on treating Markdown conversion as a formatting operation rather than a complete sanitization boundary.
Common defensive patterns include:
- Escape or encode HTML-significant characters when serializing text nodes
- Apply a context-appropriate, allowlist-based sanitizer to the final rendered HTML
- Disable or tightly restrict raw HTML support in Markdown renderers where it is not required
- Keep untrusted content in a data-only rendering context instead of injecting it as markup
- Separate trusted and untrusted content pipelines and apply least-privilege browser policies such as restrictive Content Security Policy controls
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis rules that identify Markdown-to-HTML flows lacking final output sanitization
- Code review checks for serializers that escape selected Markdown characters but preserve
<and> - Security tests covering entity-decoded text and content from special HTML parsing contexts
- Dynamic tests that verify generated Markdown cannot introduce active HTML when rendered
- Policy enforcement requiring approved, context-aware sanitizers before untrusted Markdown is displayed
Automated code review and dependency analysis tools may help identify unsafe rendering paths, but should be complemented by end-to-end output-encoding tests.

