vibe-audit.lab

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

. Then watch what your initialisation code does — in the vulnerable version, network calls or rendered links point at the probe value. A clean result (config read from your module constant, probe inert) is the pass. Add the probe markup to your sanitiser's regression corpus: future sanitiser updates must keep rejecting or neutralising it.

Worked example: PageSmith, a website builder

PageSmith (fictional), hosting about 3,900 small-business sites, let users embed custom HTML blocks — sanitised for scripts but permissive with forms. A scan flagged DOM-clobbering patterns in the builder's own runtime templates. The security review demonstrated the issue on a test site: an embedded form with id='config' and an input named 'apiUrl' redirected the site's contact-form submissions to an external endpoint, because the runtime read its configuration from a window-level name the form had shadowed. PageSmith moved runtime config into module scope, renamed its own template ids to a prefixed scheme (ps-config), taught the sanitiser to strip id/name collisions with a reserved list, and added the probe block to its sanitiser tests.

Five actions to take today

  1. Inventory the global names your scripts trust (config, settings, api, location, submit…) and grep templates for id/name collisions with them.
  2. Move configuration and state into module scope or closures; never read trusted values from window-level names.
  3. Reference elements only via explicit getElementById/querySelector lookups, and type-check values before use — fail closed on elements.
  4. Teach your HTML sanitiser to strip or rename reserved ids/names in user-supplied markup.
  5. Add the form-clobbering probe to your sanitiser and runtime regression tests, and re-scan generated templates for collisions.

Sources

  • OWASP Top 10, the OWASP Foundation's standard awareness list of the most critical web application security risks: owasp.org, 2021
  • CWE-89: Improper Neutralization of Special Elements used in an SQL Command, MITRE's weakness entry for SQL injection and its mitigations: cwe.mitre.org, 2026
  • OWASP Cheat Sheet Series — Secrets Management, OWASP's best-practice guide to storing, rotating and auditing secrets: cheatsheetseries.owasp.org, 2026

Frequently asked questions

If we sanitise user HTML, are we safe?

Sanitisers focus on script execution; a form and an input look harmless and often pass. Clobbering needs no script — which is why code-level immunity (not trusting window names) is required alongside sanitisation.

Does using a framework like React prevent this?

Frameworks reduce direct window reads but do not repeal the browser's named-property behaviour; code that reads globals, and third-party widgets, remain exposed. The reserved-name discipline still applies to your templates.

Why would legitimate code read window.config?

Older patterns inject server config as a global for convenience, and generated code copies them. The modern replacement — a module exporting a frozen config object — removes the entire collision surface.

What names are most dangerous to collide with?

Any your code reads: config/settings objects, location, top, self, document-level names, and form control names like submit and action that shadow built-in methods and properties.

Related guides

Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.


Informational explainer, not a security guarantee. Scan your code free before every deploy.

← all guides

← Back