Overview
Direct Answer
Cross-Site Scripting (XSS) is a web application vulnerability that enables attackers to inject malicious JavaScript or HTML code into web pages, which executes in the browsers of legitimate users who visit the compromised or attacker-controlled site. This injection occurs when user input is rendered without proper sanitisation or encoding.
How It Works
An attacker crafts malicious script payloads and submits them through vulnerable input vectors—such as search fields, comments, or URL parameters—which the application stores or reflects back to other users. When a victim's browser loads the page, the injected script executes within their session context, granting the attacker access to session cookies, authentication tokens, or the ability to perform unauthorised actions on behalf of the user.
Why It Matters
XSS attacks directly compromise user trust and organisational reputation, exposing sensitive customer data and enabling credential theft. Enterprises face regulatory compliance penalties under data protection frameworks and operational costs associated with incident response, remediation, and potential legal liability.
Common Applications
XSS vulnerabilities are prevalent in web applications including content management systems, social media platforms, email services, and e-commerce sites where user-generated content or query parameters are processed. Attackers exploit these vectors to harvest credentials, distribute malware, or launch phishing campaigns targeting end-users.
Key Considerations
Effective mitigation requires both client-side defences (Content Security Policy headers) and server-side protections (input validation, output encoding, templating engines). Context-aware encoding and strict separation of code and data are essential, as different encoding schemes apply depending on whether content appears in HTML, JavaScript, or URL contexts.
More in Cybersecurity
Threat Hunting
Defensive SecurityThe proactive search for cyber threats within an organisation's environment that have evaded automated detection, using hypotheses, threat intelligence, and advanced analytics.
Security Operations Centre
Defensive SecurityA centralised facility where security professionals monitor, detect, analyse, and respond to cybersecurity incidents.
Threat Modelling
Security GovernanceA structured approach for identifying, quantifying, and addressing security threats to a system or application.
Endpoint Detection and Response
Defensive SecuritySecurity technology that monitors endpoint devices to detect, investigate, and respond to cyber threats.
NIST Cybersecurity Framework
Security GovernanceA set of voluntary guidelines for managing and reducing cybersecurity risk developed by the US National Institute of Standards.
Information Security
Security GovernanceThe practice of protecting information by mitigating information risks including unauthorised access, use, and disruption.
Phishing-Resistant Authentication
Identity & AccessAuthentication methods such as FIDO2 passkeys and hardware security keys that are immune to phishing attacks because credentials are cryptographically bound to the legitimate service.
Attack Vector
Offensive SecurityThe specific path, method, or scenario used by an attacker to gain unauthorised access to a system.