XSS
Injecting script into a page so it runs in other users' browsers with the site's origin and privileges.
XSS comes in three forms. Reflected: input in the request is echoed into the response. Stored: input is saved and served to others later. DOM: client-side code moves attacker-controlled data (URL fragment, postMessage) into a sink such as innerHTML. In all cases the script runs as your origin, so it can read the page, call your APIs and steal tokens held in JavaScript-accessible storage.
Primary defence is context-aware output encoding by default (React, Angular and modern templates do this) plus sanitisation where HTML is genuinely allowed. Then layer strict CSP and Trusted Types so that a missed encoding does not become code execution.
Where it still ships: dangerouslySetInnerHTML and v-html, markdown renderers, URL attributes accepting javascript:, server-rendered JSON in script tags, and mutation XSS where a sanitiser's output is re-parsed differently by the browser.
Learn it properly
Compared
Also used in
- What happens when you log inSecEng · Foundations of Security EngineeringFree
- Identity: authentication, authorisation and tokensSecEng · Foundations of Security EngineeringFree
- Building AI features into security platformsSecEng · AI, vibe coding & logic structuringFree
- Cookies and session hardening in the browserSecEng · Browser & web platform securityFree
- SQL injection for defendersSecEng · Offensive web security for defendersFree
- Cross-site scripting for defendersSecEng · Offensive web security for defendersFree
- Access control, path traversal and file uploadsSecEng · Offensive web security for defendersFree
- Design a file upload validatorLLD · Problems: input handling componentsFree