Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 38 ยท Common Vulnerability Workflows

Cross-Site Scripting (XSS) Testing Workflow

A safe workflow for finding cross-site scripting with Burp: inject a harmless marker, find where it lands, judge the context, and recommend output encoding and CSP.

Cross-site scripting (XSS) lets an attacker's script run inside a victim's browser, in the context of the vulnerable site. That script can read the page, perform actions as the user, and in the worst cases take over the account. XSS appears when an application puts untrusted data into a page without encoding it for the place where it lands.

This lesson teaches the testing workflow in Burp using a harmless marker rather than a weaponised script, and shows how to reason about context. The Burp screens are labelled example output; the Python blocks are offline stand-ins. Test only authorised systems.

The three kinds

Type How the data arrives Example
Reflected Comes from the current request and is echoed straight back A search page showing "Results for: your term"
Stored Saved on the server and shown to other users later A comment or profile field
DOM-based JavaScript in the page reads a source (URL fragment, location) and writes it to a sink (innerHTML) without the server being involved A client-side router

The workflow

flowchart TD
  A["1. Inject a unique<br/>harmless marker"] --> B["2. Search responses<br/>for the marker"]
  B --> C["3. Identify the context<br/>(HTML, attribute, JS, URL)"]
  C --> D["4. Test whether<br/>context-breaking characters<br/>survive unencoded"]
  D --> E["5. Confirm with a<br/>benign proof in the browser"]
  E --> F["6. Report with<br/>context and fix"]

The key question is always: where does my input land, and what characters can I still use there?

Step 1 and 2: a unique marker

Send a value like xk4917zz in every parameter. Use Burp's search (Proxy history filter, or the response search box in Repeater) to find where xk4917zz appears in responses. If it is reflected, note every occurrence. Intruder or the scanner's insertion points can do this at scale.

Step 3: identify the context

The same input is dangerous or harmless depending on where it lands:

Context Example output What would let the input break out
HTML body <p>Hello xk4917zz</p> Angle brackets that create a new tag
HTML attribute <input value="xk4917zz"> A closing quote that ends the attribute
JavaScript string var q = 'xk4917zz'; A quote or a closing script tag
URL (href) <a href="xk4917zz"> A javascript: scheme
CSS style="color: xk4917zz" Rarely exploitable in modern browsers

Test with the special characters that matter in that context: a probe like xk4917zz"'<> shows which characters come back raw and which are encoded (&quot;, &lt;).

See context-aware encoding

This stand-in prints what happens to a probe when the application encodes correctly for the HTML body and incorrectly in an attribute. It uses only the Python standard library.

Python Which characters survive? (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In the wrong version a raw double quote survives, so an attacker could end the attribute and add their own. The right version encodes the quote as &quot;. Your Burp evidence for a finding is exactly this: a context-breaking character came back unencoded.

Step 5: confirm

Once a context-breaking character survives, confirm in a real browser with a benign proof, for example a payload that only changes the page title or shows an alert on your own test session. Pasting the URL into a browser and seeing your marker act as markup is enough. Take a screenshot as evidence. Keep Burp's Proxy on so the exact request is saved.

For stored XSS, submit the marker, then view the page as another (test) user, because the trigger is on a different page. Remember cleanup: delete your test comment afterwards.

For DOM XSS, view the page source and the script files. Search for sinks such as innerHTML, document.write, eval and location handling. Burp's DOM Invader (in the built-in browser) automates this by tracking sources into sinks.

Why blocklists fail

A filter that removes <script> tags is easy to bypass with event attributes (onerror, onload), SVG, or different casing and encodings. This is why recommendations never say "filter bad words".

The fix

  1. Output-encode by context: HTML-encode in the body, attribute-encode in attributes, JavaScript-encode in scripts, URL-encode in URLs. Use the template engine's auto-escaping (Blade {{ }}, Jinja2 autoescape, React JSX) and avoid raw-output features.
  2. Never put untrusted data in script blocks or event handlers; pass it as JSON data in a safe attribute.
  3. Validate URLs and allow only https: and http: schemes in links.
  4. Add a Content Security Policy (script-src 'self' with nonces) as defence in depth.
  5. Set cookies HttpOnly so script cannot read session cookies, and SameSite to limit cross-site use.
  6. For rich text, use a maintained sanitiser with an allow-list, never regular expressions.

A CSP header is worth reporting as missing, but it is not a substitute for encoding. Treat it as a seatbelt, not the brakes.

Writing the finding

Include the request, the exact location and context of the reflection, which characters survived, the browser proof (screenshot), whether it is reflected, stored or DOM, who is affected (all users who see the comment, or only someone who clicks a crafted link), and the fix. Severity depends on reach: stored XSS on a page every user views outranks reflected XSS needing a specially crafted link. See writing findings.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why use a unique harmless marker as the first probe?

    A unique string is easy to search for and shows where input is reflected.
  2. 2. Which type of XSS is saved on the server and shown to other users?

    Stored XSS persists on the server and triggers when other users view the content.
  3. 3. In an HTML attribute context, which character matters most?

    A raw quote lets the input end the attribute and add new ones.
  4. 4. What is the primary defence against XSS?

    Encoding output for its context ensures data is treated as text, not markup.
  5. 5. What does a Content Security Policy provide?

    CSP limits script execution if encoding fails, but does not replace it.

Summary

  • XSS comes in reflected, stored and DOM-based forms, and all depend on unencoded data in a context.
  • Inject a unique marker, find reflections, identify the context, and see which special characters survive.
  • Confirm with a benign browser proof and screenshot; for stored XSS use a second test user.
  • Fix with context-aware encoding and auto-escaping templates, plus CSP, HttpOnly cookies and sanitisers.
  • Tests belong on authorised systems; the Python blocks are offline stand-ins.

Next: Access control and IDOR testing