Skip to content

LearnWeb and API

Reflected XSS testing by output context

Brief

A parameter that comes back in the page is a finding only once we know which context it lands in and whether the one character that matters there survives. One marker answers the first question, one character the second, and one script call that shows only our engagement marker is the whole proof.

Stage
Access
Reviewed
On this page
  1. Check first
  2. Where does the parameter land in the response?
  3. Does the server encode the one character that matters in that context?
  4. What do the response headers do about it?
  5. What is the least-impact proof?
  6. The defender sees
  7. Done when
  8. Not covered
  9. Tools
  10. Related research
  11. Reviewed

All commands

Situation
A request from the first hour whose parameter value appears in the response, a proxy, and a browser profile signed in to our own test account on an application named in the scope letter. Every probe carries the marker atarus7f3a, every proof runs in our own session, and nothing is sent to another user or left stored.
Goal
A reflection table: for each parameter, the context it lands in, whether the character that matters there is encoded, the response headers that limit it, and the proof URL.
Outputs
Captured on 4 Nov 2026 against the Atarus Bench Web and API lab fixture, edition web-api-0.2, running on loopback, with one origin playing every host, renamed to the example domains and printed as https (the lab ran plain http). The dialog in the proof step runs in a browser and is not part of the capture.

Check first

  • Every parameter that comes back in a response: query, body, path segments, and headers such as Referer and User-Agent.
  • The content type of each response it lands in, because text/html and application/json are different problems.
  • Whether the application sends a Content-Security-Policy, and what it allows for scripts.
  • A browser profile signed in to our own test account, so the proof runs in nobody else's session.
  • Two agreed strings: atarus7f3a for probes and ATARUS-TEST-2026-10-27 for the proof.

Steps

Where does the parameter land in the response?

M=atarus7f3a
for p in q lang ref; do
  curl -s "https://app.example.com/search?$p=$M" -A "$M-agent" \
    | grep -o ".\{40\}$M.\{40\}" | sed "s|^|$p: |"
done
curl -s -o /dev/null -w '%{content_type}\n' "https://app.example.com/api/search?q=$M"

Expected output

q: page" id="main-content"><h2>Results for atarus7f3a</h2><p>No results matched your search, 
q: orm"><input type="text" name="q" value="atarus7f3a" class="search-box" autocomplete="off">
lang: e for this page:</p><script>var lang = "atarus7f3a"; initPage(lang);</script><noscript>Scr   # <- a JavaScript string: the context with the widest reach
ref: href="https://app.example.com/back?from=atarus7f3a" class="back">Back</a> to the previous 
application/json; charset=utf-8

The marker has no special characters, so nothing filters it, and the grep prints every landing with forty characters of context on each side. One parameter often lands twice, as q does in the heading and the search box, and each landing is its own row: HTML body, attribute value, script string, URL, or a JSON value. The request also sends the marker as its user agent, because headers reflect too.

Negative result. The marker appears nowhere, or only inside a JSON value of a response the browser never renders as a page.

Fix. Know every place input is written into a response and let the template engine encode it. Jinja autoescapes .html templates in Flask, Django escapes <, >, ', " and & in every variable, Go's html/template escapes by context, and React DOM escapes values embedded in JSX. The dangerous lines are the ones that opt out: |safe, Markup, dangerouslySetInnerHTML, and string concatenation into a script block.

Does the server encode the one character that matters in that context?

curl -s "https://app.example.com/search?q=${M}%3Cx" | grep -o "$M.\{6\}" | sort -u
curl -s "https://app.example.com/search?lang=${M}%22x" | grep -o ".\{20\}$M.\{20\}"

Expected output

atarus7f3a&lt;x"
atarus7f3a&lt;x<
<script>var lang = "atarus7f3a"x"; initPage(lang);   # <- the quote comes back raw: the string can be closed

One character per context is enough. For the body and attribute landings we send <; both landings of q encode it, so those contexts hold. For the script string we send ", and it comes back unchanged, which means the string closes and whatever follows runs as code. A URL context is tested with javascript: only when the value is the whole attribute, and a JSON context is tested by its content type in the headers step, not by a character.

Negative result. Every character comes back as an entity or a JavaScript escape such as \x22 or \".

Fix. Encode for the context the value lands in: HTML entity encoding for body and quoted attributes, JavaScript escaping for strings, and URL encoding for parameters. Better than a JavaScript string is a data- attribute or a JSON script block that code reads, so no user value is written into executable text at all.

What do the response headers do about it?

curl -sI "https://app.example.com/search?q=$M" | grep -iE '^(content-type|content-security-policy|x-content-type-options)'
curl -sI "https://app.example.com/api/search?q=$M" | grep -iE '^(content-type|x-content-type-options)'

Expected output

Content-Type: text/html; charset=utf-8
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' https://cdn.example.net   # <- 'unsafe-inline' means an injected inline script is allowed
Content-Type: application/json; charset=utf-8

A policy with 'unsafe-inline', or no policy, leaves the proof unobstructed. The API response is JSON, which is safe only while browsers treat it as JSON: without X-Content-Type-Options: nosniff an older client or an odd content type can turn an echoed value into a rendered page.

Negative result. A script-src built on a per-response nonce with 'strict-dynamic' and no 'unsafe-inline', and nosniff on both responses.

Fix. Send Content-Security-Policy: script-src 'nonce-<random per response>' 'strict-dynamic'; object-src 'none'; base-uri 'none', start in report-only mode with a reporting endpoint, and add X-Content-Type-Options: nosniff everywhere. A policy is a limit, not a cure: the PolyShell skimmer left through WebRTC, which connect-src does not govern, so the encoding fix comes first.

What is the least-impact proof?

curl -s 'https://app.example.com/search?lang=%22%3Balert(%22ATARUS-TEST-2026-10-27%22)%3B%2F%2F' \
  | grep -o ".\{20\}ATARUS-TEST.\{30\}"

Expected output

ar lang = "";alert("ATARUS-TEST-2026-10-27");//"; initPage(la   # <- our call sits inside the page's own script block

We open that URL in the browser profile signed in as our test account and screenshot the dialog, which shows the marker and nothing else. That is the whole proof: one call that reads nothing, sends nothing anywhere, and runs for nobody but us. The same call serves every confirmed context, placed by closing that context, and we write it once per context rather than collecting variants.

Negative result. The quote is escaped in the response and no dialog appears. A dialog blocked only by the policy is still a finding, with the policy recorded as the control that held.

Fix. Encoding from the second step, the policy from the third, and a regression test that sends the marker through every reflected parameter on each build.

The defender sees

The marker probes carry no special characters and pass any filter; they are ordinary lines in the application log with atarus7f3a in the query string, which is how the client finds them afterwards. The character probes and the proof are what a WAF sees, and neither carries a script tag, so the client's logs decide what fired. A request AWS WAF's core rule set judges as cross-site scripting is labelled awswaf:managed:aws:core-rule-set:CrossSiteScripting_QueryArguments and blocked; a ModSecurity deployment with the OWASP Core Rule Set logs a rule from its 941 group with the request id, most likely 941100, "XSS Attack Detected via libinjection", since 941110, "XSS Filter - Category 1: Script Tag Vector", wants a <script> tag we never send. The dialog leaves no server trace, because it runs in our browser. Where the policy has a reporting endpoint, the blocked inline script, or in report-only mode the one that would have been blocked, arrives there as a violation report naming the page and the directive. A WAF block with the encoding still missing is two findings, since the application is unfixed and every filter has a bypass; a WAF that fired and a team that did not look is a third.

Done when

Every reflected parameter has a row with its context and encoding result, the content type and policy headers are recorded, and one proof URL shows the marker dialog in our own browser.

Not covered

Stored and DOM-based cross-site scripting, and any impact after the proof such as session theft.