Web & application

XSS

Cross-Site Scripting

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

Related terms