llamaCVEVulnerability Intelligence
/
Advisory · GitHub · PyPI · justhtml

GHSA-6CR7-H2Q7-28P7

Uncaught ValueError denial of service via non-ASCII Unicode digit in numeric HTML entity

Texto original en inglés · Ver en español

Parche disponible
Descargar PNG JSON
CVSS
—
high
Fuente: —
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche el mismo día de la divulgación
Exposición12 dDesde la divulgación, 9 nov 2026, 5:08 p. m.
Detección8 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaSeguir
Remediar en la ventana regular de mantenimiento
Estimación de Llama con el árbol SSVC de CISA a partir de la severidad declarada por GHSA (alta) y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, no automatizable e impacto técnico parcial. Hay versiones corregidas disponibles.
Ojo con los rangos de versión, son traicioneros.Esto amerita una regla de detección, por si acaso.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Parche 3.17.0
Monitoreo
Detectada +1
9 nov 26
18 nov 26
21 nov 26
9 nov 26
12 nov 26
15 nov 26
18 nov 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-6CR7-H2Q7-28P7 divulgada
Remediación Parche 3.17.0 justhtml · 0 d desde divulgación
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Summary

The HTML entity decoder in justhtml crashes with an uncaught `ValueError` when it parses a numeric character reference whose digits contain a non-ASCII Unicode digit, such as the superscript two character `²` (U+00B2). The decimal digit collector at `src/justhtml/core/entities.py:286` uses Python's `str.isdigit()`, which accepts any character with Unicode `Numeric_Type=Digit`, but the downstream conversion `int(digits, 10)` at `src/justhtml/core/entities.py:215` only accepts strict ASCII decimal digits and raises `ValueError` for the rest. Any caller that parses untrusted HTML through the public `JustHTML(...)` constructor or the `stream(...)` API is affected; no authentication, no special configuration, and no user interaction are required. A 4 byte payload (`&#²;`) reliably aborts parsing, producing a denial of service.

Root Cause

justhtml promises in its security policy that small hostile inputs must not trigger uncaught conversion errors while parsing. The decimal numeric character reference path violates that invariant. When the decoder encounters `&#`, it collects the digit run with `while j < length and text[j].isdigit()`. `str.isdigit()` returns `True` for a broad set of Unicode characters beyond ASCII `0` through `9`, including superscripts (`¹`, `²`, `³`), subscripts (`₀`, `₁`, `₂`, `₃`), and other `Numeric_Type=Digit` code points. The collected string is then handed to `decode_numeric_entity`, which calls `int(digits, 10)`. `int()` with an explicit base only accepts characters where `str.isdecimal()` is `True`, so a collected non-decimal Unicode digit makes `int()` raise `ValueError`. The collector and the consumer disagree about what a "digit" is, so the validator admits a character the consumer cannot process.

Affected function: decode_entities_in_text (src/justhtml/core/entities.py)
  - digit collector:  src/justhtml/core/entities.py:286  while text[j].isdigit()
  - failing sink:      src/justhtml/core/entities.py:215  int(digits, base)  (base=10)
Helper: decode_numeric_entity (src/justhtml/core/entities.py), invoked at src/justhtml/core/entities.py:295

The hexadecimal path at `src/justhtml/core/entities.py:283` uses an explicit ASCII character set (`"0123456789abcdefABCDEF"`), so `&#x...;` references are not affected. The length guard at `src/justhtml/core/entities.py:212` only rejects digit runs longer than 16 characters, so a single non-decimal digit passes it unchanged.

Impact

An unauthenticated attacker who can supply HTML to an application that parses it with justhtml can crash the parser on demand. The payload is minimal (`&#²;`, 4 bytes in UTF-8), deterministic on every request, and works in both HTML text and attribute values. Because the `ValueError` is not caught anywhere in the parser or its public entry points, it propagates out of `JustHTML(...)` and `stream(...)` to the caller. In a typical web service that parses or sanitizes user-submitted HTML inline on a request, each malicious request aborts the handling of that request, and an attacker can repeat it to deny service. There is no confidentiality or integrity impact: the flaw aborts processing rather than exposing or altering data. The semicolon is optional (`&#²` also triggers the crash).

Proof of Concept

Any supported Python 3 interpreter with justhtml installed. No additional dependencies.

Install justhtml and run:

from justhtml import JustHTML, stream

# Constructor path: raises ValueError
JustHTML("&#\u00b2;", fragment=True)

# Streaming API path: also raises ValueError
list(stream("&#\u00b2;"))

# Attribute-value path: also raises ValueError
JustHTML('<a title="&#\u00b2;">x</a>', fragment=True)
Traceback (most recent call last):
  ...
  File ".../justhtml/core/entities.py", line 215, in decode_numeric_entity
    codepoint = int(digits, base)
ValueError: invalid literal for int() with base 10: '²'

The underlying type mismatch is directly observable in a plain interpreter:

>>> '²'.isdigit()
True
>>> '²'.isdecimal()
False
>>> int('²', 10)
ValueError: invalid literal for int() with base 10: '²'

Confirmed trigger characters include `²` (U+00B2), `³` (U+00B3), `¹` (U+00B9), `⁰` (U+2070), `₀` (U+2080), `₁` (U+2081), `₂` (U+2082), and `₃` (U+2083).

Attack Chain

  1. Exposure: An application parses attacker-supplied HTML through the public `JustHTML(...)` constructor (`src/justhtml/parser/__init__.py`) or `stream(...)` (`src/justhtml/parser/stream.py`). These accept arbitrary strings with no authentication or configuration gate.
  2. Control: The attacker supplies the full HTML string. The minimal payload `&#²;` places a non-ASCII Unicode digit immediately after `&#`. Python strings preserve the character; no input layer normalizes or strips it.
  3. Path: On encountering `&` in text, the parser unconditionally calls `decode_entities_in_text` (for example at `src/justhtml/parser/engine.py:2070`). The decimal branch collects the digit run at `src/justhtml/core/entities.py:286`.
  4. Guard: `str.isdigit()` at `src/justhtml/core/entities.py:286` accepts `²`, and the length guard at `src/justhtml/core/entities.py:212` passes a single character. No guard rejects the non-decimal digit before conversion.
  5. Primitive: `decode_numeric_entity` reaches `int(digits, 10)` at `src/justhtml/core/entities.py:215` and raises `ValueError`.
  6. Result: The `ValueError` propagates uncaught out of the parser and the public API, aborting the parse. Repeating the request sustains denial of service against any application parsing untrusted HTML.

Bypass Evidence

The relevant protection is the digit validation guarding the `int()` conversion. The decimal collector uses `str.isdigit()`, which is broader than the `str.isdecimal()` set that `int(..., 10)` requires, so the guard admits characters the conversion rejects. Attempts to find a protecting layer failed: no caller of `decode_entities_in_text` wraps it in a `try/except ValueError` (the `ValueError` handlers in `src/justhtml/parser/engine.py` wrap DOM `list.index`/`list.remove` operations, not entity decoding), the public constructor and stream entry points invoke the parser without catching the exception, the `lstrip("0")` and `len > 16` checks at `src/justhtml/core/entities.py:211` and `:212` leave a single-character payload unchanged, and no input normalization strips non-ASCII digits before decoding. The hexadecimal branch at `src/justhtml/core/entities.py:283` is unaffected because it uses an explicit ASCII character set. The denial-of-service hardening in advisory GHSA-r8cj-3554-33mr (fixed in 1.18.0) addressed a related `isdigit()` misuse in the linkification IPv4 path (`src/justhtml/transforms/linkify_core.py`) but never modified the entity decoder, so this path has no prior fix.

Affected Versions

  • Ecosystem: `pip`
  • Package: `justhtml`
  • Confirmed affected range: `<= 3.16.0`
  • Latest release checked: `3.16.0` (PyPI https://pypi.org/project/justhtml/3.16.0/)
  • Fix status: not fixed

The crash was reproduced on versions installed from PyPI spanning the project's entire release history, including `0.1.0`, `0.20.0`, `0.40.0`, `1.0.0`, `1.18.0`, `1.23.0`, `2.0.0`, `2.4.1`, `3.0.0`, `3.10.1`, `3.15.0`, and the latest `3.16.0`. The decimal entity decoder has used the Unicode-aware `isdigit()` collector since the earliest published release; the module was later reorganized (the decoder now lives in `core/entities.py`), but the defect predates that reorganization, so the affected range covers all releases up to and including the latest. No release fixes this path.

Suggested Fix

Collect decimal numeric character reference digits using a strict ASCII decimal test so the collector and the `int(..., 10)` consumer agree on the accepted character set. For example, restrict the decimal branch to the explicit set `"0123456789"` (mirroring the hexadecimal branch), or equivalently require `text[j].isascii() and text[j].isdecimal()`. As defense in depth, treat a numeric reference that does not convert as invalid and emit the Unicode replacement character or preserve the literal text, matching the parser's existing graceful handling of malformed references, rather than allowing the conversion error to escape. The fix must cover both HTML text and attribute-value decoding, which share the same `decode_entities_in_text` path. Until an upgrade is available, applications can bound exposure by constraining or pre-filtering untrusted HTML, but there is no configuration flag that disables the vulnerable decimal entity path.

---

Reported by zx.

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Versiones

Rangos afectados

Afectada Corregida Última
justhtml≤ 3.16.0
3.16.0
3.17.0
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
pypijusthtml
Corregida 3.17.0 0 d 3.17.0 no afectada
Versiones corregidas3.17.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/EmilStenstrom/justhtml/security/advisories/GHSA-6cr7-h2q7-28p7

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.