llamaCVEVulnerability Intelligence
/
Advisory · GitHub · npm · sanitize-html

GHSA-2RJC-9XVG-45J7

CDATA variant of GHSA-x3q4-9hxx-gx8m still bypasses the noscript discard in sanitize-html 2.18.1

Parche disponible
Descargar PNG JSON
CVSS
—
medium
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ón7 dDesde la divulgación, 11 nov 2026, 3:28 p. m.
Detección6 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Parche 2.18.2
Monitoreo
Detectada +1
11 nov 26
18 nov 26
19 nov 26
11 nov 26
13 nov 26
15 nov 26
17 nov 26
19 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-2RJC-9XVG-45J7 divulgada
Remediación Parche 2.18.2 sanitize-html · 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

GHSA-x3q4-9hxx-gx8m describes two ways to end the `<noscript>` discard region early when `noscript` is in `nonTextTags`: an implied close and a `<![CDATA[` variant. 2.18.0 fixed the implied close. The CDATA variant, which the advisory shows, still works in 2.18.1, the latest release, and on `main` (734ec4d7, the latest commit touching `packages/sanitize-html`). It also works in 2.17.7 and 2.18.0, so it was never fixed.

The same construction also hides the start tag of the default `nonTextTags` `script`, `style`, `textarea` and `xmp`, so it is not limited to applications that add `noscript`.

Details

A browser and sanitize-html read the payload in the proof of concept differently.

Outside SVG and MathML, the HTML tokenizer turns `<!CDATA[` into a bogus comment that ends at the first `>` ([markup declaration open state https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state, bogus comment state https://html.spec.whatwg.org/multipage/parsing.html#bogus-comment-state). So the `<noscript>` after it is a real start tag, and with scripting enabled everything up to `</noscript>` is raw text.

In HTML mode htmlparser2 recognizes the CDATA syntax but does not treat it as CDATA: the tokenizer reads `<![CDATA[` up to `]]>`, and `Parser.oncdata` reports the whole section as one comment (`` oncomment(`[CDATA[${value}]]`) `` in `src/Parser.ts`). sanitize-html registers no comment handler and drops it. It never sees the `<noscript>` start tag inside it, so the raw-text guard added in 2.18.0, which starts in `onopentag`, never runs, and what follows is treated as ordinary markup.

Other observations:

  • `parser: { recognizeCDATA: true }` and `xmlMode: true` do not help. The hidden start tag comes out as escaped text and the link and image still come through.
  • `disallowedTagsMode: 'recursiveEscape'` is affected too: without the CDATA section the `noscript` content comes out escaped; with it, as live markup.
  • Lowercase `<![cdata[` and an unterminated section do not reproduce, which matches the browser.
  • `option` is not affected: the browser renders that content as well.

I have not written or tested a fix. Treating a CDATA section in HTML content the way browsers do, as a comment that ends at the first `>`, while keeping real CDATA in SVG and MathML, would close this variant. Since htmlparser2's parser already reports HTML-content CDATA as a comment, the boundary could also be fixed there.

Proof of concept

sanitize-html 2.18.1 (htmlparser2 12.0.0) on Node 24:

const sanitizeHtml = require('sanitize-html');

const options = {
  allowedTags: ['p', 'a', 'img'],
  allowedAttributes: { a: ['href'], img: ['src'] },
  nonTextTags: ['script', 'style', 'textarea', 'option', 'noscript'],
};

sanitizeHtml(
  '<p>Hi</p><![CDATA[ x > <noscript>]]><a href="https://evil.test">Reset your password</a><img src="https://evil.test/beacon.gif"></noscript>',
  options,
);
// => '<p>Hi</p><a href="https://evil.test">Reset your password</a><img src="https://evil.test/beacon.gif" />'

// For comparison, the implied-close variant is fixed:
sanitizeHtml('<div><noscript></div><img src="https://evil.test/t.gif"></noscript>', {
  ...options,
  allowedTags: ['div', 'img'],
});
// => '<div></div>'

Default options, same construction with `style` (`textarea`, `xmp` and `script` behave the same):

sanitizeHtml('<p>Hi</p><![CDATA[ x > <style>]]><a href="https://evil.test">Reset your password</a></style>');
// => '<p>Hi</p><a href="https://evil.test">Reset your password</a>'

// Without the CDATA section the style content is discarded:
sanitizeHtml('<p>Hi</p><style><a href="https://evil.test">Reset your password</a></style>');
// => '<p>Hi</p>'

parse5 7.3.0 with `scriptingEnabled: true` parses the first input's body as `<p>Hi</p>`, the comment `[CDATA[ x `, a space, and a `<noscript>` whose only child is the text `]]><a href="https://evil.test">Reset your password</a><img src="https://evil.test/beacon.gif">`. Chrome 152 (input loaded through an iframe `srcdoc`) renders no link and no image for any of these inputs; the sanitized output has them. Results are the same on 2.17.7, 2.18.0, 2.18.1 and `main`.

Impact

The same as GHSA-x3q4-9hxx-gx8m: input can make sanitize-html emit elements that the browser would have kept inert inside `noscript`, `style`, `textarea`, `xmp` or `script`. Only tags, attributes and URL schemes the allowlist permits get through (here a link and a tracking image); no script runs. An attacker who controls the whole input can also submit allowlisted markup directly, so this matters where an application relies on sanitize-html discarding the content of those elements. I rated it Moderate, as the GitHub Advisory Database rates GHSA-x3q4-9hxx-gx8m (CVSS 4.0: 5.3).

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

Versiones

Rangos afectados

Afectada Corregida Última
sanitize-html< 2.18.2
2.18.2
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
npmsanitize-html
Corregida 2.18.2 0 d 2.18.2 no afectada
Versiones corregidas2.18.2
Explotación

Arsenal público

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

Referencias
Advisoryhttps://github.com/apostrophecms/apostrophe/security/advisories/GHSA-2rjc-9xvg-45j7

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