cross-site scripting
An attack where hostile script is injected into a trusted web page and runs with that page’s access, for example to read data or cookies.
Injected script can act as the user and read anything the page can.
In more detail
HttpOnly cookies limit what injected script can steal, but the real fix is encoding output and validating input so the script never runs. Stored, reflected and DOM-based variants differ only in where the hostile script comes from.
Example
React escapes values it renders, but dangerouslySetInnerHTML and unsafe third-party scripts bypass that.Related terms
- HttpOnly — A cookie attribute that stops scripts running in the page from reading the cookie, while the browser still sends it on requests.
- SQL injection — An attack where untrusted input is joined into a database query so that part of it runs as SQL, letting an attacker read or change data.
- input sanitization — Cleaning input by removing or escaping dangerous parts, such as HTML tags, before storing or displaying it.
- untrusted input — Any data a program did not create itself, including arguments, form fields, request bodies, file contents, file names and environment variables.
Taught in
- Cookies And CORS — Modern API Architecture: REST, GraphQL & gRPC
- Session Management: Secure Cookies & Token Validation — Next.js 15 & Modern App Router Architecture