Course contentsShow
← Security
Lesson 651 of 3,05214. Web Security - XSS and Content InjectionFree lesson

Event Handler Obfuscation

Evading filters using alternative event handlers, inline event attributes, and less common JavaScript execution contexts.

Event Handler Obfuscation

What you'll learn: How attackers evade XSS filters by using obscure event handlers and alternative JavaScript execution contexts instead of obvious ones.

The Core Idea

When security filters block common XSS vectors like <script> tags or onclick handlers, attackers turn to less-monitored event handlers and unusual execution contexts. Think of it like a burglar who finds the front door locked, so they check every window, the basement door, and even the chimney—any entry point that's not being watched as carefully.

Why Event Handlers Matter

HTML supports dozens of event handlers beyond the familiar onclick or onload. Many filters only blacklist the most common ones, leaving alternatives wide open. Additionally, event handlers can be placed on nearly any HTML element, creating numerous injection opportunities.

Alternative Event Handlers

Instead of blocked handlers, attackers use:

  • onmouseover, onmouseout, onmousemove (triggered by mouse movement)
  • onerror (fires when resources fail to load)
  • onanimationstart, onanimationend (CSS animation events)
  • ontransitionend (CSS transition events)
  • onfocus, onblur (element focus changes)
  • oninput, onchange (form input events)

Inline Attributes and Unusual Contexts

Attackers also exploit:

  • Less common tags: <svg onload=...>, <body onpageshow=...>, <marquee onstart=...>
  • Inline styles with expressions: (older browsers)
  • Data attributes combined with framework hooks: Exploiting how JavaScript frameworks bind events

Example Pattern

A filter might block <img src=x onerror=alert(1)> but miss <svg><animate onbegin=alert(1)> or <input autofocus onfocus=alert(1)>.

Key Takeaway: Attackers bypass XSS filters by substituting blocked event handlers with less common alternatives and leveraging obscure HTML elements and execution contexts that evade detection.