guides · 2026-11-14
DOM Clobbering: How a Form Field Named 'config' Silently Replaces Your JavaScript Objects
Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team
The short answer
Named elements become named properties: a form with id='config' creates window.config, and an input named 'apiUrl' inside it creates config.apiUrl — as an element, not your object. If any markup an attacker influences (stored HTML, ads, comments, imported content) can carry ids or names, it can clobber the globals and objects your scripts read. Defend by never trusting window-level names, using explicit lookups, and sanitising stored markup.
Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.
A browser feature from a friendlier era
The behaviour is specified, not a bug: document exposes named elements, forms expose their controls by name, and window collects ids as globals. Legacy conveniences, all of them — and they compose badly with modern code that does things like if (window.config) init(config.apiUrl) or reads form.action-style properties assuming the types it set. The clobbering payload needs no script at all: pure HTML — a form element with id='config' containing an input named 'apiUrl' whose value is an attacker URL — turns config.apiUrl into a string read from that input's value (via the element's own properties) or into the element itself where a URL was expected. Vibe-Code Audit's DOM-clobbering detector flags named elements shadowing JS globals because AI-generated pages and templates routinely emit ids like config, settings, location and submit — names chosen for readability that are loaded weapons in the browser's namespace.
What an attacker does with a shadowed global
Realistic outcomes: configuration objects replaced so API calls go to the attacker's endpoint; feature flags and allow-lists read from elements instead of code; form.submit shadowed by a button named submit (the charming classic that breaks handlers and bypasses their checks); sanitiser and security-library globals undermined where a page composes third-party widgets. The precondition is any channel by which attacker-influenced markup reaches a page — stored profile fields rendered as HTML, imported templates, embedded third-party content — which makes clobbering the second act of a stored-markup problem: the sanitiser let the tags through because they looked harmless (a form! an input!), and there was no script to strip.
What is DOM clobbering?
a browser behaviour where HTML elements with id or name attributes become accessible as properties of window, document or their parent form — allowing markup to shadow JavaScript variables and configuration objects that code reads as if they were its own.
Coding patterns that are immune
Stop reading configuration and state from the window namespace: keep app config in module scope or a closure, reference elements exclusively through getElementById/querySelector with explicit variables, and validate types before trusting values (a config that is an HTMLElement is not a config — fail closed). Where code must check for globals, use Object.prototype.hasOwnProperty or compare against values you set yourself earlier in the same script. Sanitising stored markup remains layer one (strip or rename dangerous ids/names in user content), but the code-level immunity matters because markup sources multiply — ads, embeds, partner widgets — beyond any single sanitiser's jurisdiction.
In code review, the sweep is simple: grep templates for id= and name= colliding with your global vocabulary (config, settings, api, location, top, self, submit, action, method), and grep scripts for bare reads of those names. Generated HTML loves semantic ids; your job is making sure semantic never means shadowed.
Testing for collisions
In staging, inject the canonical probe through the same channel users can influence: markup carrying