💫Event Based XSS

In JavaScript, several events can be used to trigger Cross-Site Scripting (XSS) payloads

- onabort: This event is triggered when an image fails to load.
- onerror: This event is triggered when an error occurs or an image fails to load.
- onload: This event is triggered when an object has loaded.
- onchange: This event is triggered when the content of a form element, the selection, or the checked state has changed (for <input>, <select>, <textarea>).
- onsubmit: This event is triggered when a form is submitted.
- onreset: This event is triggered when a form is reset.
- onselect: This event is triggered after some text has been selected in an element.
- onblur: This event is triggered when an element loses focus.
- onfocus: This event is triggered when an element receives focus.Pyload= "onfocus=alert(1337) autofocus="
- onkeydown: This event is triggered when a key is pressed.
- onkeypress: This event is triggered when a key is pressed and released.
- onkeyup: This event is triggered when a key is released.
- onclick: This event is triggered when an element is clicked.
- ondblclick: This event is triggered when an element is double-clicked.
- onmousedown: This event is triggered when a mouse button is pressed.
- onmousemove: This event is triggered when the mouse is moved.
- onmouseout: This event is triggered when the mouse is moved off an element.
- onmouseover: This event is triggered when the mouse is moved over an element.
- onmouseup: This event is triggered when a mouse button is released.

---------------------------------------------------------------

Standard HTML events

Tag Attribute
Tags supported
Note

onload

body, iframe, img, frameset, input, script, style, link, svg

Great for 0-click, but super commonly filtered

onpageshow

body

Great for 0-click, but appears only usable in Non-DOM injections

onfocus

input, select, a

for 0-click: use together with autofocus=""

onerror

img, input, object, link, script, video, audio

make sure to pass params to make it fail

onanimationstart

Combine with any element that can be animated

Fired then a CSS animation starts

onanimationend

Combine with any element that can be animated

Fires when a CSS animation ends

onstart

marquee

Fires on marquee animation start - Firefox only?

onfinish

marquee

Fires on marquee animation end - Firefox only?

ontoggle

details

Must have the ‘open’ attribute for 0-click

Situational HTML events

Tag Attribute
Tags supported
Note

onmessage

most tags

postMessage is commonly used to get around iframe restrictions and share data, as a result if your page is doing this you can use onmessage to intercept messages and trigger code

onblur

input, select, a

Set autofocus="" for an easy 1-click when the user switches focus away from the injected element by clicking on anything on the page

Examples:

---------------------------------------------------------------

HTML5 events

Name
Tags
Note

onplay

video, audio

For 0-click: combine with autoplay HTML attribute and combine with valid video/audio clip

onplaying

video, audio

For 0-click: combine with autoplay HTML attribute and combine with valid video/audio clip

oncanplay

video, audio

Must link to a valid video/audio clip

onloadeddata

video, audio

Must link to a valid video/audio clip

onloadedmetadata

video, audio

Must link to a valid video/audio clip

onprogress

video, audio

Must link to a valid video/audio clip

onloadstart

video, audio

Great underexploited 0-click vector

oncanplay

video, audio

Must link to a valid video/audio clip

Examples:

---------------------------------------------------------------

CSS-based Injection

True XSS injection through CSS is dead (for now). The following are XSS vectors that depend on CSS stylesheets or are otherwise enhanced by them.

Name
Tags
Note

onmouseover

most tags

Will trigger when mouse moves over the injected element. If possible, add styling to make it as big as possible. It’s technically a 0-click if you don’t have to click, right? /s

onclick

most tags

Will trigger when user clicks on element. If possible, add styling to make it as big as possible.

onanimationstart & onanimationend

most tags

Triggers on start or end of a CSS animation, which you can make happen on page load (0-click).

Note: Below uses style tags to set up keyframes for animation(start|end), but you can also check for already included CSS to reuse what’s already there by using e.g. animation: alreadydefined;. It doesn’t matter what the animation is, just that it exists.

Payload that injects an invisible overlay that will trigger a payload if anywhere on the page is clicked:

Same, but for moving your mouse anywhere over the page (0-click-ish):

---------------------------------------------------------------

HTML Tags

Event handlers

Last updated