Definition
Cross-Site Scripting (XSS) is a web application vulnerability that allows attackers to inject malicious client-side scripts into web pages viewed by other users, enabling session hijacking, defacement, or malicious redirects.
People Also Ask
Common questions about Cross-Site Scripting (XSS) answered by our security experts.
Cross-Site Scripting (XSS) in Practice
Cross-site scripting occurs when an application includes untrusted input in a page without neutralising it, so that the input executes as script in another user's browser.
The victim is the user rather than the server, which is why it is sometimes underrated. In practice it yields session theft, credential capture and actions performed as the victim, which is account takeover by another route.
The three forms
Stored — the payload is saved by the application and served to everyone who views the affected content. The most serious, because it requires no interaction from the victim beyond normal use.
Reflected — the payload is in the request and echoed into the response, requiring the victim to follow a crafted link. Document-based — the flaw is in client-side code manipulating the page, and the payload may never reach the server at all, which means server-side logging shows nothing.
What it achieves
Reading session cookies, unless they are marked inaccessible to script. Capturing keystrokes and form input on the affected page, including credentials. Performing actions as the victim, with their full privileges.
Modifying page content to phish convincingly, from the genuine domain with a valid certificate. That last case is why it is a serious finding even where no data is directly read.
The fix is contextual output encoding
Encoding depends on where the data lands. Text within a page, an attribute value, a script block, a style and a URL each require different treatment, and applying the wrong one leaves the flaw open.
Modern frameworks encode by default, which has reduced this substantially. The residual risk sits in the places developers deliberately bypass that default — inserting raw markup, building HTML by hand, or passing content through functions that interpret it.
Defence in depth around it
A content security policy restricts which scripts may execute, which can neutralise injected script even where the flaw exists. It takes effort to deploy on an existing application and is valuable.
Session cookies marked inaccessible to script remove the simplest payoff. Requiring re-authentication for sensitive actions means a stolen session cannot change credentials or payment details.
Finding it
Dynamic testing and manual testing are effective, because the flaw is observable in the response. Static analysis helps with server-side cases and struggles with client-side ones.
The document-based form needs client-side analysis specifically, and is regularly missed by testing that only examines server responses — worth confirming is in scope when commissioning an application test.
Related injection in the browser
Two neighbours are worth knowing. Request forgery causes a victim’s browser to perform an authenticated action they did not intend, and is addressed by anti-forgery tokens and appropriate cookie policy.
Clickjacking overlays or frames your page so a user clicks something other than what they see, and is addressed by frame-ancestor restrictions. Both exploit the browser’s willingness to attach credentials to requests, and both are configuration rather than code changes.
Where to start
Search your front-end code for the places where raw markup is inserted deliberately, bypassing framework encoding. That short list is where this flaw now lives.
See web application firewalls. GuardsArm delivers application penetration testing.
Related Terms
SQL Injection
SQL Injection is a code injection attack that exploits vulnerabilities in an application's database layer by inserting malicious SQL statements into input fields, allowing attackers to read, modify, or delete database contents.
Web Application Firewall (WAF)
A Web Application Firewall (WAF) is a security solution that monitors, filters, and blocks HTTP/HTTPS traffic to and from web applications, protecting against attacks like SQL injection, XSS, and other OWASP Top 10 vulnerabilities.
OWASP Top 10
The OWASP Top 10 is a regularly updated awareness document listing the ten most critical web application security risks, serving as the industry standard for web application security testing and developer training.
Related Reading
Database Security: Protecting Your Most Valuable Data Assets
The database holds everything an attacker wants, and its controls are usually weaker than the application in front of it. Accounts, network reach…
API Rate Limiting for Patient Portals: Stopping Abuse Early
Credential stuffing, account enumeration and scraping all look like ordinary traffic one request at a time. Rate limiting is what makes the pattern…
What We Actually Find in Healthcare Penetration Tests
The same handful of issues, in hospital after hospital. None of them exotic, all of them a path from one workstation to the patient record.
Speak With an Expert
Book a free consultation to discuss cross-site scripting (xss) for your organization.
Related Services
Need Help With Cross-Site Scripting (XSS)?
Our certified security professionals can help you implement the right cross-site scripting (xss) strategy for your organization. Get a free assessment today.