cross-site scripting
An attack in which someone gets their own script to run inside your page, where it can read data, act as the user or steal tokens.
Script running in your origin can do anything the logged-in user can do.
In more detail
XSS stands for cross-site scripting. It happens when untrusted input is inserted into a page as code, for example through innerHTML or an unescaped template. Defences include textContent, output encoding, Content Security Policy and Trusted Types.
Example
In the course a search term <script>steal()</script> is reflected unescaped into the page.Related terms
- DOM-based XSS — Cross-site scripting that happens entirely in the browser, when page JavaScript copies attacker-controlled data, such as part of the URL, into a dangerous sink.
- Content Security Policy — An HTTP response header that tells the browser which sources of scripts and other content a page may load, limiting what injected markup can do.
- Trusted Types — A browser security feature that makes dangerous DOM sinks such as innerHTML reject plain strings and accept only values produced by a policy you define.
- innerHTML — The DOM property that reads or replaces an element's contents as an HTML string, which the browser parses into nodes.
- HttpOnly — A cookie attribute that stops scripts running in the page from reading the cookie, while the browser still sends it on requests.
- localStorage — A browser feature that saves small text values for a website so they are still there after the page is closed and reopened.
- cross-site request forgery — An attack where another website makes the victim's browser send a request to your site, and the browser's cookie makes it look genuine.
- output encoding — Converting data into a safe form for the exact place it is written, such as HTML text or an attribute, so the browser shows it instead of running it.
- HTML — The markup language that describes the structure and meaning of a web page with elements such as <button>, <input> and <h2>.
Taught in
- DOM Manipulation: DocumentFragment And HTML Templates — Frontend Architecture & Web Platform
- Client Storage Paradigms: Cookies, Storage Tradeoffs — Frontend Architecture & Web Platform
- Same-Origin Policy, CORS Preflight, Credentials And Headers — Frontend Architecture & Web Platform
- Content Security Policy (CSP), Trusted Types And XSS Defenses — Frontend Architecture & Web Platform
- Session Architecture: HTTP-Only Cookies vs Tokens — Production Full-Stack Engineering
- Cross-Site Scripting — Application Security & Threat Modeling for Engineers
- Dynamic Scanning — Application Security & Threat Modeling for Engineers
- Simulation: Placing The Controls — CompTIA Security+ (SY0-801) Exam Prep
References
- OWASP: Cross Site Scripting
- MDN: Cross-site scripting
- OWASP Cross Site Scripting Prevention Cheat Sheet
- CWE-79: Cross-site Scripting