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 onwindow/document— can break scripts expecting undefined. - CSP and sanitization reduce injection vectors.
- Avoid
document.xpatterns; usegetElementById. - Legacy apps and third-party HTML embeds are vulnerable.