Cross-site scripting (XSS) occurs when untrusted input is rendered by a browser as active content instead of inert text, letting an attacker execute JavaScript in the context of another user’s session. It comes in three forms that require different testing approaches: reflected, stored and DOM-based.
Reflected and stored XSS: testing with Burp Suite
Reflected XSS returns attacker input immediately in the response, usually from a URL parameter. Stored XSS saves the input (a comment, a profile field) and serves it to other users later, making it more severe. A standard, low-impact confirmation payload testers use is:
<script>alert(document.domain)</script>
Using Burp Suite’s Intruder, testers can send a list of context-aware payload variants against every parameter systematically, since encoding and filtering behaviour often differs from field to field:
<img src=x onerror=alert(document.domain)>
"><svg onload=alert(document.domain)>
javascript:alert(document.domain)
Burp’s built-in Scanner also flags likely XSS automatically by inserting canary strings and checking whether they are reflected unescaped in HTML, attribute, or script contexts, which narrows down where manual confirmation is needed.
DOM-based XSS: a different bug class
DOM-based XSS never touches the server; the vulnerable code runs entirely in client-side JavaScript. A common vulnerable pattern:
// VULNERABLE: untrusted source written to a dangerous sink
const name = new URLSearchParams(location.search).get('name');
document.getElementById('greeting').innerHTML = "Hello, " + name;
Testers trace “sources” (URL, document.referrer, postMessage data) to “sinks” (innerHTML, document.write, eval) using Burp’s DOM Invader extension or by manually reviewing bundled JavaScript, since this class is invisible to server-side logging.
The fix: encode on output, by context
The DOM-based example above is fixed by using a safe property instead of a dangerous sink:
// FIXED: textContent does not interpret HTML
document.getElementById('greeting').textContent = "Hello, " + name;
On the server side, encode output according to where it lands: HTML-entity encoding for HTML body content, attribute encoding inside tag attributes, and JavaScript-string encoding inside inline scripts. Most modern frameworks (React, Vue, Angular) auto-escape by default; the risk reappears specifically where a developer opts out, such as React’s dangerouslySetInnerHTML or Angular’s bypassSecurityTrustHtml, which should be treated as a flag for manual review.
Content-Security-Policy as a safety net
A strict Content-Security-Policy header limits the damage even if an encoding mistake slips through, by telling the browser which script sources are allowed to execute:
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0mBase64Value'; object-src 'none'; base-uri 'self'
Avoid 'unsafe-inline' and 'unsafe-eval' wherever possible; they disable the exact protection CSP is meant to provide. A nonce-based policy, with a fresh random nonce generated per response and applied to legitimate script tags, allows trusted inline scripts while blocking injected ones.
How Egaros can help
We test for reflected, stored and DOM-based XSS across modern single-page applications and traditional server-rendered sites, and provide concrete, framework-specific fixes. Contact us to schedule a test.


اترك تعليقاً