Dev.Lib
arrow_backBack to Blogs
LEVEL_066.3June 27, 20261 min read

DOM clobbering

Web Security

Named elements (`<img name="x">`) inject properties on `window`/`document` — can break scripts expecting undefined.

Summary

Named elements (<img name="x">) inject properties on window/document — can break scripts expecting undefined. CSP and sanitization reduce injection vectors. Avoid document.x patterns; use getElementById. Legacy apps and third-party HTML embeds are vulnerable.

Code example

// Avoid: document.config — clobberable by injected named elements
const config = document.getElementById('app-config')?.dataset;

// Prefer explicit IDs over named DOM lookups

Key points

  • Named elements (<img name="x">) inject properties on window/document — can break scripts expecting undefined.
  • CSP and sanitization reduce injection vectors.
  • Avoid document.x patterns; use getElementById.
  • Legacy apps and third-party HTML embeds are vulnerable.

Further reading

Related concepts