igbuend/grimbard/dom-clobbering-anti-pattern
Claude Code and agent skill by igbuend/grimbard
- community
Checking that the SKILL.md file is still in the repository.
Security anti-pattern for DOM Clobbering vulnerabilities (CWE-79 variant). Use when generating or reviewing code that accesses DOM elements by ID, uses global variables, or relies on document properties. Detects HTML injection that overwrites JavaScript globals.
Install
npx vskill@latest install igbuend/grimbard/dom-clobbering-anti-patternSKILL.md
DOM Clobbering Anti-Pattern
Severity: Medium
Summary
DOM Clobbering overwrites global JavaScript variables via attacker-controlled HTML. Browsers auto-create global variables from id and name attributes. Enables logic bypasses, XSS, and security control evasion. Bypasses HTML sanitizers that allow id and name.
The Anti-Pattern
Application JavaScript relies on global variables that HTML injection overwrites. Code expects legitimate objects but receives DOM element references instead.
BAD Code Example
GOOD Code Example
React Example
BAD:
GOOD:
TypeScript Example
GOOD:
Detection
JavaScript Patterns:
- Global variable access:
window.config,document.userInfo - Implicit globals:
config.isAdmin(no var/let/const declaration) document.getElementById()without type validation- Security checks on globals:
if (window.auth.isLoggedIn)
Search Patterns:
- Grep:
window\.[a-zA-Z]+\.|\bdocument\.[a-zA-Z]+\.|getElementById\(.*\)\.(?!tag|class) - Look for:
if (window.orif (document. - Check: Direct property access without instanceof check
HTML Sanitizer Review:
- DOMPurify: Check
FORBID_ATTRdoesn't excludeid,name - Sanitize-html: Review
allowedAttributesconfig - HTML Purifier: Verify attribute whitelist
Manual Testing:
- Identify global variables: Check
windowobject in console - Inject clobbering HTML:
<div id="globalVarName"></div> - Verify override:
console.log(typeof window.globalVarName) - Test security impact: Try bypassing checks
Prevention
- [ ] Avoid using global variables for security-critical operations or configurations. Instead, use a private namespace (e.g.,
const myApp = { config: { ... } };). - [ ] Freeze critical objects using
Object.freeze()to make them read-only, preventing them from being overwritten. - [ ] Validate the type of any object retrieved from the DOM before using it (e.g.,
if (elem instanceof HTMLFormElement)). - [ ] Use a robust HTML sanitizer, but be aware that allowing
idandnameattributes still leaves you vulnerable. DOM Clobbering protection must be implemented in your JavaScript code. - [ ] Use prefixes for element IDs that are unlikely to collide with global variables (e.g.,
id="myapp-user-form").
Testing for DOM Clobbering
Manual Testing:
- Identify globals: Open browser console, type
window.and check autocomplete - Test clobbering: Inject
<div id="targetGlobal"></div>via input fields - Verify type change:
typeof window.targetGlobalshould show object → object (Element) - Test bypass: Check if security checks fail (admin access, auth bypass)
Automated Testing:
- Static Analysis: ESLint plugin
eslint-plugin-no-unsanitized - Dynamic Testing: Burp Suite DOM Clobbering scanner
- Code Review: Search for
window.access patterns - Type Checking: TypeScript strict mode catches many cases
Example Test:
Browser DevTools Check:
Remediation Steps
- Identify global dependencies - Search for
window.and implicit globals - Audit HTML sanitizer - Check if
idandnameare allowed - Create namespace - Move globals to module scope or namespace object
- Add type validation - Check
instanceofbefore using DOM elements - Freeze critical objects - Use
Object.freeze()on config objects - Update code - Replace
window.foowithmyApp.foo - Test protection - Verify clobbering attempts fail
- Enable TypeScript - Leverage type safety for additional protection
Related Security Patterns & Anti-Patterns
- Cross-Site Scripting (XSS) Anti-Pattern: DOM Clobbering can be a vector to enable XSS.
- Mutation XSS Anti-Pattern: Another sanitizer-bypass technique that abuses the way browsers parse HTML.
- Missing Input Validation Anti-Pattern: Failing to validate the type of a DOM element is a form of missing input validation.
References
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/dom-clobbering-anti-pattern/SKILL.md
Popularity
- Repository stars
- 4
- Repository forks
- 1
- 7-day trend score
- 8
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 29 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/igbuend/grimbard/dom-clobbering-anti-pattern)