GHSA-5vp3-3cg6-2rq3: Justhtml Cross-Site Scripting Vulnerability

HIGH
CWE-80 CWE-79
Published
Advisory Summary

GHSA-5vp3-3cg6-2rq3 is a HIGH cross-site scripting vulnerability (CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)) affecting Justhtml libraries in the PyPI ecosystem. The issue involves justhtml is vulnerable to xss via code fence breakout in <pre> content. Remediation is available by upgrading affected packages to version 1.13.0.

GHSA-5vp3-3cg6-2rq3 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-5vp3-3cg6-2rq3
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)
Affected Product Justhtml
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix GHSA-5vp3-3cg6-2rq3

To remediate this vulnerability, upgrade all affected Justhtml dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

justhtml fixed: 1.13.0
pip install justhtml>=1.13.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show justhtml

How to Check if You Are Affected

To determine whether your Python environment is affected by GHSA-5vp3-3cg6-2rq3, inspect your installed packages using pip:

pip show justhtml

Analyze the terminal output to locate any version of Justhtml in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.13.0), your application is affected.

Note: The pip show justhtml command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS), where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages. In Justhtml, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary `to_markdown()` is vulnerable when serializing attacker-controlled `<pre>` content. The `<pre>` handler emits a fixed three-backtick fenced code block, but writes decoded text content into that fence without choosing a delimiter longer than any backtick run inside the content. An attacker can place backticks and HTML-like text inside a sanitized `<pre>` element so that the generated Markdown closes the fence early and leaves raw HTML outside the code block. When that Markdown is rendered by a CommonMark/GFM-style renderer that allows raw HTML, the HTML executes. This is a bypass of the v1.12.0 Markdown hardening. That fix escaped HTML-significant characters for regular text nodes, but `<pre>` uses a separate serialization path and does not apply the same protection. ## Details The vulnerable `<pre>` Markdown path: - extracts decoded text from the `<pre>` subtree - opens a fenced block with a fixed delimiter of `````` - writes the decoded text directly into the output - closes with another fixed `````` Because the fence length is fixed, attacker-controlled content containing a backtick run of length 3 or more can terminate the code block. If the content also contains decoded HTML-like text such as `&lt;img ...&gt;`, that text appears outside the fence in the resulting Markdown and is treated as raw HTML by downstream Markdown renderers. The issue is not that HTML-like text appears inside code blocks. The issue is that the serializer allows attacker-controlled `<pre>` text to break out of the fixed fence. ## Reproduction ```python from justhtml import JustHTML payload = "<pre>&#96;&#96;&#96;\n&lt;img src=x onerror=alert(1)&gt;</pre>" doc = JustHTML(payload, fragment=True) # default sanitize=True print(doc.to_html(pretty=False)) # <pre>``` # &lt;img src=x onerror=alert(1)&gt;</pre> print(doc.to_markdown()) # ``` # ``` # <img src=x onerror=alert(1)> # ``` ``` Rendered as CommonMark/GFM-style Markdown, that output is interpreted as: 1. Line 1 opens a fenced code block 2. Line 2 closes it 3. Line 3 is raw HTML outside the fence 4. Line 4 opens a new fence ## Impact Applications that treat `JustHTML(..., sanitize=True).to_markdown()` output as safe for direct rendering in Markdown contexts may be exposed to XSS, depending on the downstream Markdown renderer's raw-HTML handling. ## Root Cause The `<pre>` Markdown serializer uses a fixed fence instead of selecting a delimiter longer than the longest backtick run in the content. ## Fix When serializing `<pre>` content to Markdown, choose a fence length longer than any backtick run present in the code block content, with a minimum length of 3.

GHSA-5vp3-3cg6-2rq3 Affected Justhtml Versions

1 component(s)
Fixed Versions:
1.13.0
Product / Package Ecosystem Affected Versions Fixed Version
justhtml
PyPI
< 1.13.0
1.13.0

References

Frequently Asked Questions

What is GHSA-5vp3-3cg6-2rq3?
GHSA-5vp3-3cg6-2rq3 is a security vulnerability in Justhtml involving JustHTML is vulnerable to XSS via code fence breakout in <pre> content under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS).
Which Justhtml versions are affected?
Affected versions include releases prior to 1.13.0 across affected packages: justhtml.
What version fixes GHSA-5vp3-3cg6-2rq3?
Upgrading to 1.13.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is justhtml affected?
Yes, justhtml is affected in releases prior to 1.13.0. Upgrade your dependency to 1.13.0 or later.
What CWE is associated with GHSA-5vp3-3cg6-2rq3?
GHSA-5vp3-3cg6-2rq3 is classified under CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages.).
How can I check PyPI dependencies for GHSA-5vp3-3cg6-2rq3?
Run the dependency tree command: 'pip show justhtml'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5vp3-3cg6-2rq3",
  "modified" : "2026-03-24T19:22:21Z",
  "published" : "2026-03-24T19:22:21Z",
  "aliases" : [ ],
  "summary" : "JustHTML is vulnerable to XSS via code fence breakout in <pre> content",
  "details" : "## Summary\n\n`to_markdown()` is vulnerable when serializing attacker-controlled `<pre>` content. The `<pre>` handler emits a fixed three-backtick fenced code block, but writes decoded text content into that fence without choosing a delimiter longer than any backtick run inside the content.\n\nAn attacker can place backticks and HTML-like text inside a sanitized `<pre>` element so that the generated Markdown closes the fence early and leaves raw HTML outside the code block. When that Markdown is rendered by a CommonMark/GFM-style renderer that allows raw HTML, the HTML executes.\n\nThis is a bypass of the v1.12.0 Markdown hardening. That fix escaped HTML-significant characters for regular text nodes, but `<pre>` uses a separate serialization path and does not apply the same protection.\n\n## Details\n\nThe vulnerable `<pre>` Markdown path:\n\n- extracts decoded text from the `<pre>` subtree\n- opens a fenced block with a fixed delimiter of ``````\n- writes the decoded text directly into the output\n- closes with another fixed ``````\n\nBecause the fence length is fixed, attacker-controlled content containing a backtick run of length 3 or more can terminate the code block. If the content also contains decoded HTML-like text such as `&lt;img ...&gt;`, that text appears outside the fence in the resulting Markdown and is treated as raw HTML by downstream Markdown renderers.\n\nThe issue is not that HTML-like text appears inside code blocks. The issue is that the serializer allows attacker-controlled `<pre>` text to break out of the fixed fence.\n\n## Reproduction\n\n```python\nfrom justhtml import JustHTML\n\npayload = \"<pre>&#96;&#96;&#96;\\n&lt;img src=x onerror=alert(1)&gt;</pre>\"\ndoc = JustHTML(payload, fragment=True)  # default sanitize=True\n\nprint(doc.to_html(pretty=False))\n# <pre>```\n# &lt;img src=x onerror=alert(1)&gt;</pre>\n\nprint(doc.to_markdown())\n# ```\n# ```\n# <img src=x onerror=alert(1)>\n# ```\n\n```\n\nRendered as CommonMark/GFM-style Markdown, that output is interpreted as:\n\n1. Line 1 opens a fenced code block\n2. Line 2 closes it\n3. Line 3 is raw HTML outside the fence\n4. Line 4 opens a new fence\n\n## Impact\n\nApplications that treat `JustHTML(..., sanitize=True).to_markdown()` output as safe for direct rendering in Markdown contexts may be exposed to XSS, depending on the downstream Markdown renderer's raw-HTML handling.\n\n## Root Cause\n\nThe `<pre>` Markdown serializer uses a fixed fence instead of selecting a delimiter longer than the longest backtick run in the content.\n\n## Fix\n\nWhen serializing `<pre>` content to Markdown, choose a fence length longer than any backtick run present in the code block content, with a minimum length of 3.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "justhtml"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.13.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 1.12.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/EmilStenstrom/justhtml/security/advisories/GHSA-5vp3-3cg6-2rq3"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/EmilStenstrom/justhtml/commit/f35f8f723c713bd8f912d86e9ec6881275ff5af9"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/EmilStenstrom/justhtml"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/EmilStenstrom/justhtml/releases/tag/v1.13.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79", "CWE-80" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-24T19:22:21Z",
    "nvd_published_at" : null
  }
}