October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

What Is DOM Clobbering? How HTML Names Can Confuse JavaScript

DOM clobbering occurs when named HTML elements collide with properties JavaScript expects on browser objects. Learn the vulnerable patterns and practical defenses.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

DOM clobbering is a browser behavior that can become a security vulnerability when named HTML elements collide with properties that JavaScript expects to find on objects such as window or document. The browser may return an element or collection where an application expects configuration or another value. It does not automatically reassign every JavaScript variable: risk arises when untrusted markup creates a collision and existing code trusts the result.

How can an HTML element affect a JavaScript lookup?

Browsers expose certain elements through named properties, often based on an element’s id or name. As a result, code that reads a property such as window.redirectTo can receive a reference to a matching element instead of the application value it expected. The precise result depends on the browser’s named-property behavior and the markup involved.

This is not the same as changing a local variable declared with let or const. The vulnerable pattern is a lookup through a clobberable browser object, followed by code that assumes the returned value has a particular meaning or type.

When does DOM clobbering become a vulnerability?

Clobbering matters when an attacker can influence HTML that reaches the DOM and application code makes an unsafe property lookup. The markup need not contain a script: the technique can remain relevant even when a filter or sanitizer blocks direct script injection but allows attacker-controlled names or attributes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • A collision: An element’s name matches a property the code reads.
  • Unsafe use: The application treats the resulting element or collection as trusted configuration, a URL, or another expected value.
  • A useful impact: The altered value affects a sensitive operation, such as navigation, script loading, or filtering.

Without an exploitable collision and a vulnerable use of the value, the presence of an element with a particular name is not, by itself, proof of a security issue.

What can an attacker influence?

Navigation and configuration

OWASP describes code that uses window.redirectTo || '/profile/' as a navigation destination. If attacker-controlled markup creates a matching named property, the lookup may yield an element whose URL-related value can influence navigation. OWASP also describes a clobbered configuration property affecting a dynamically created script URL. These examples show why code should not treat a browser-global property as trusted configuration simply because it exists.

Collections and script URLs

PortSwigger demonstrates how repeated anchor IDs can produce a collection, and how a named child property of that collection can be used as a script URL by vulnerable code. The important lesson is the unexpected shape of the returned value: code may receive a collection or element where it assumes it has a safe configuration object.

Filtering logic

PortSwigger also documents a form-based case in which an injected input named attributes interferes with code that expects a form’s attributes collection while filtering markup. This shows that DOM properties used in security-sensitive filtering need validation too; a property name alone does not guarantee the expected interface or behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What can DOM clobbering lead to?

The impact depends on the vulnerable data flow. It may cause unexpected behavior or redirects; in some cases, it can help reach script execution by influencing a script URL or another security-sensitive operation. DOM clobbering does not automatically mean that a page has cross-site scripting (XSS), and the cited sources do not establish a prevalence figure that would justify a numerical estimate.

How should developers prevent it?

Sanitize untrusted HTML at the boundary

Sanitize HTML before inserting it into the DOM. OWASP recommends DOMPurify or the Sanitizer API. DOMPurify’s default SANITIZE_DOM setting addresses collisions with built-in APIs and properties. OWASP also notes that setting SANITIZE_NAMED_PROPS: true isolates custom names by prefixing them with user-content-. That stronger namespacing can affect features that rely on the original IDs or names, so choose the setting with the application’s legitimate markup needs in mind.

If using the Sanitizer API, configure it to block id and name attributes where that fits the feature. OWASP cautions that the API’s default configuration does not itself prevent DOM clobbering. Confirm support in the browsers your application targets before depending on it; a current compatibility matrix is not established by the cited guidance.

Keep sensitive state out of named globals

Store configuration in local lexical variables or encapsulated application state rather than relying on names exposed through window or document. Explicit let and const declarations help avoid accidental globals, but they do not protect a separate property such as window.NAME if code still reads from it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate values at the point of use

Before using values from window, document, or DOM properties in sensitive operations, check that they have the expected type and behavior. PortSwigger gives checking for an expected DOM interface as an example. Apply validation to the actual operation: a value used as a URL, a configuration object, or a filtering collection should meet the relevant expectations before the code trusts it.

Use CSP as an additional layer

A Content Security Policy (CSP) can restrict some attempts to load new scripts, but it does not repair unsafe use of values by code that is already running. Treat CSP as defense in depth, alongside sanitization, safer state management, and validation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which defense belongs at which layer?

Defense Where it acts What it helps address Important limitation
HTML sanitization When untrusted markup enters the application Removes or isolates hostile markup and names; DOMPurify can address DOM clobbering, with SANITIZE_NAMED_PROPS: true available for custom-name isolation Sanitizer configuration can affect legitimate uses of id and name; the Sanitizer API’s default configuration does not itself prevent clobbering
Safer scoping and explicit state Application code Reduces reliance on clobberable window or document names Does not secure a separate named property that code continues to read
Type and interface validation At sensitive use sites Catches an unexpected element or collection before the application treats it as another kind of value Must match the operation and expected value; it does not remove hostile markup
CSP Browser enforcement of script-loading and execution rules Can limit some attacks that attempt to load a new script Does not prevent every misuse of values by code that is already running

No one measure covers every vulnerable use. A robust design sanitizes untrusted HTML, avoids security-sensitive named globals, and validates values before acting on them; CSP can provide an additional restriction on certain execution paths.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.