## Cross-Site Scripting ### Basics - Attacker injects script into **another site** (cross-site) - e.g., using HTML code containing JavaScript - Goal: Usually, steal sensitive information of the user (attack confidentiality) - Script runs in *origin* of vulnerable site - Confused-deputy attack (all privileges of the browser/origin) - **Dimensions**: - Persistence of injected code (reflected vs. persistent) - Location of the vulnerable code (server vs. client) - Main problem: - *Data interpreted as code* (basically for all injection attacks) - Browser trusts the received code - Main attack against websites - Countermeasure: Sanitization ![](images/xss-dimensions.png) ![](images/xss-consequence.png) ### History & Attacks - 1997: First attack found (by IAS) - XSS was not *discovered* - 1999: Discovered (Reflected SSXSS in 404 Pages) - 2005: Name proposed - Initially, DOM-based XSS - Nowadays called Client-side cross-site scripting - 2005: MySpace Worm (SS P XSS) - Attack: Inject HTML in profile page - Payload added Samy Kamkar as friend - Injected code for friends - 2013: Ubuntu Forums (SS P XSS) - Vulnerability in vBulletin software - XSS in announcements (sent link to admins) - Attacker stole cookies - 2014: Password managers - Browsers auto-fill forms - Attack: Fill form, wait for browser to fill ### Impact - Capabilities of JS in *its context* (powerful): - Full control over DOM - Full access to browser state (e.g., cookies, storage, ...) - Read/write HTTP requests within the SOP - JS can pretend to be the - User towards server (e.g., post content) - Server towards user (e.g., modify page behavior) - Possible attack: **Session Hijacking** - Also called *Session ID Theft* - Goal: Steal session cookie of the user - XSS can be used to perform a session hijacking attack - Mitigation: Use HTTPOnly cookies ### Injection - Primary methods for script injections - Inline scripts - External scripts (e.g., attacker controls CDN) - `eval(attackerinput)` - Examples: - Tag injection - `$var` - `$var = ''` - Break out of attributes - `` - `$var = 'foo.jpg" onerror="javascript:alert(1)'` - Javascript URLs - `