XSS Payload Tester & Cross-Site Scripting Checker
Test your form fields, URL parameters, and API inputs against real XSS payloads, see which ones execute, and get the exact escaping or CSP fix for each vulnerability.
Understanding Cross-Site Scripting (XSS) Vulnerabilities
Cross-Site Scripting (XSS) is a critical security vulnerability where an attacker injects malicious client-side scripts (usually JavaScript) into otherwise trusted websites. XSS remains a fixture on the OWASP Top 10 web application vulnerabilities because a single unescaped output point can compromise a user's entire session. When a victim's browser executes the injected script, the attacker gains the ability to steal session cookies, hijack active accounts, capture keystrokes, modify page content via DOM manipulation, or redirect the user to phishing portals.
To properly defend applications, security teams must categorize XSS into three primary vectors:
- Reflected XSS: The malicious script is part of the request sent to the server (e.g., a search parameter) and is echoed back in the response immediately.
- Stored XSS: The payload is saved on the server's database (e.g., a forum post, user profile name) and executes when other users fetch and render that content.
- DOM-Based XSS: The vulnerability exists entirely in client-side code, where JavaScript reads input from an untrusted source (like
location.hash) and writes it directly to an unsafe sink (likeelement.innerHTML).
How it Works: The XSS Execution and Sanitization Mechanics
To understand how an XSS attack succeeds, it is helpful to look at how web browsers parse HTML. An HTML document is a structured tree of nodes. If an application prints user input directly into this document without escaping, the browser cannot distinguish between intended structure and user content. If you write <script>alert(1)</script>, the HTML parser reads the < character and immediately switches to script parsing mode, executing the instructions.
Preventing XSS requires context-aware output escaping:
- HTML Body Context: Convert special characters into safe HTML entities. For example,
<becomes<,>becomes>, and&becomes&. The browser displays the character visually but does not parse it as executable markup. - Attribute Context: When outputting values inside quoted tag attributes (e.g.,
<input value="USER_INPUT">), attackers attempt to breakout using double quotes:" onfocus="alert(1). To prevent this, double quotes (") must be encoded as"and single quotes (') as'. - JavaScript Context: When inserting server variables into inline
<script>tags, standard HTML escaping is ineffective. Attackers can breakout using closing tags (</script>). Values must be serialized safely (e.g., using JSON serialization) and characters like\must be escaped.
Worked Examples: 5 Common Attack Vectors and Fixes
Example 1: Classic Script Tag Injection
- Payload:
<script>alert(document.cookie)</script> - Mechanics: Directly forces the browser to open a scripting block. If session cookies lack the
HttpOnlyflag, the script can extract and transmit them to an external server. - Remediation: HTML-entity encode
<to<and>to>.
Example 2: Attribute Breakout & Event Handler
- Payload:
"><img src=x onerror=alert(1)> - Mechanics: The leading
"closes the current attribute, and the>closes the current tag. The attacker then injects a new<img>element with a broken source (src=x) which automatically triggers theonerrorevent handler to run the script. - Remediation: Encode
"to"and sanitize tag attributes.
Example 3: JavaScript URI Sink
- Payload:
javascript:alert(document.domain) - Mechanics: When injected into a hyperlink
<a href="USER_INPUT">, clicking the link triggers the browser's JavaScript protocol interpreter instead of navigating to a website. - Remediation: Enforce a strict protocol allowlist (e.g., only allow
http://orhttps://schemes).
Example 4: SVG Script Bypass
- Payload:
<svg/onload=alert(1)> - Mechanics: Bypasses basic filters that search only for
<script>tags. The SVG element loads and immediately triggers its inlineonloadhandler. - Remediation: Use robust parsing libraries like DOMPurify to strip unauthorized attributes.
Example 5: HTML Entity Bypass
- Payload:
<script>alert(1)</script> - Mechanics: Useful if the application decodes HTML entities after filtering but before rendering into the DOM, reconstituting the executable tags.
- Remediation: Never perform double decoding of inputs; sanitize at the final output boundary.
Comparison: XSS Mitigation Strategies
| Mitigation Method | Implementation Difficulty | Security Level | Limitations |
|---|---|---|---|
| HTML Entity Escaping | Easy (Built-in framework defaults) | High (For body contexts) | Fails in JavaScript and attribute contexts if incorrect quotes are used |
| DOMPurify Sanitization | Moderate (Requires third-party library) | Very High (Great for rich text) | Minor performance overhead for large documents |
| Content Security Policy (CSP) | High (Requires server header tuning) | Very High (Defense-in-depth) | Can be bypassed if unsafe-inline or loose CDN domains are allowlisted |
| Input Blocklist Filtering | Easy | Low (Easily bypassed by obfuscation) | Highly prone to bypasses; not recommended |
Edge Cases, Sanitization Bypass, and CSP Limitations
Experienced attackers use complex formatting rules to bypass standard filters:
- Mutation XSS (mXSS): Browsers try to repair broken HTML before rendering it in the DOM. An attacker can write an inert payload that, when parsed and normalized by the browser, transforms into an active XSS exploit. Standard regex filters cannot predict how a browser will mutate HTML.
- Nested Event Handlers & Polyglots: Attackers construct payloads that function in multiple contexts simultaneously (e.g., working inside an attribute, a script tag, and a plain body at the same time). Stripping single keywords like
scriptcan be bypassed by nesting (e.g.,<sc<script>ript>). - Loose Content Security Policies: If a site allowlists a broad CDN (like
cdnjs.cloudflare.com) in itsscript-srcdirective, attackers can bypass CSP by loading old, vulnerable library files (such as angular.js) to execute arbitrary code via client-side template injection.
Key Benefits & Features
Test script tags, event handlers, javascript: URIs, SVG vectors, and encoded bypasses — not just the textbook example.
See instantly whether each payload runs as live script or is neutralized as plain text in a sandboxed preview.
Each result explains the vector and the exact remediation: HTML entity escaping, attribute encoding, or a CSP directive.
Payloads are evaluated in an isolated sandbox in your browser. Nothing is uploaded, logged, or stored.
How to Use the XSS Payload Tester Step-by-Step
This utility runs entirely inside your browser using client-side JavaScript. We prioritize your security: none of your inputted text is logged or stored.
- 1
Paste a value from your form, URL parameter, or API field — or pick a payload from the built-in attack library.
- 2
Choose the output context you want to test: HTML body, HTML attribute, URL, or JavaScript string.
- 3
Run the payload and watch the sandboxed preview to see whether it executes or renders as inert text.
- 4
Read the verdict and apply the recommended escaping or CSP fix, then re-test to confirm the input is now safe.
Practical Examples
<script>alert(document.cookie)</script>
"><img src=x onerror=alert(1)>
javascript:alert(1)
<svg/onload=alert(1)>
<script>alert(1)</script>
Frequently Asked Questions (FAQ)
What is an XSS payload tester and who should use it?▼
An XSS payload tester lets you fire known cross-site scripting attack strings at your application's inputs to see whether they execute or get safely escaped. It's for developers, QA engineers, and security testers who want to validate input sanitization on their own authorized applications before a real attacker probes them. Only test sites and inputs you own or have permission to assess.
What is the difference between reflected, stored, and DOM-based XSS?▼
Reflected XSS echoes a malicious value from the request straight back into the response (e.g. a search term shown on the results page). Stored XSS saves the payload — in a comment, profile, or database record — so it runs for every user who later views it, making it the most damaging. DOM-based XSS never reaches the server: client-side JavaScript reads an untrusted value (like location.hash) and writes it into the DOM with innerHTML or similar sinks. This tool helps you reproduce all three by testing how a value behaves in each output context.
How do I actually fix an XSS vulnerability once I find one?▼
Escape on output based on context: HTML-entity-encode < > & " ' when writing into HTML, use attribute encoding inside tag attributes, and never build DOM with innerHTML from untrusted data — use textContent or a sanitizer like DOMPurify. Reject dangerous URL schemes (javascript:, data:) in href/src. Finally, add a Content Security Policy that blocks inline scripts as a defense-in-depth layer so a missed escape can't execute.
Does a Content Security Policy stop XSS on its own?▼
A strict CSP (for example, script-src 'self' with no 'unsafe-inline') is a strong second line of defense — it can stop injected inline scripts from running even if an input slips through. But CSP is not a substitute for output escaping: misconfigurations, allowlisted CDNs, and DOM sinks can still be abused. Use both. Test your inputs here, then use our Security Headers Auditor to confirm your CSP is present and correctly configured.
Is it safe to run these payloads in this tool?▼
Yes. Payloads are evaluated inside an isolated browser sandbox purely to demonstrate behavior — nothing is sent to a server, logged, or stored. The point is to show you what your own application would do with the same input so you can fix it.
Browse our full list of free security & cryptography and make your daily content, coding, or math tasks easier.
Related Tools & Utilities
Related Security & Cryptography
View allSimulate diagnostic port connection checklists (e.g. 80, 443, 22, 21, 3306).
Audit safety headers like CSP, HSTS, XSS protection, and frame protections.
Build Content-Security-Policy headers interactively with directive toggles.
Generate Apache .htaccess redirect rules (301, 302, rewrite) with bulk support.