CROSS-SITE SCRIPTING (XSS) XSS persists because context, parser, and framework edges are complex. Treat every user-influenced string as untrusted until it is strictly encoded for the exact sink and guarded by runtime policy (CSP/Trusted Types). - Reflected, stored, and DOM-based XSS across web/mobile/desktop shells - Multi-context injections: HTML, attribute, URL, JS, CSS, SVG/MathML, Markdown, PDF - Framework-specific sinks (React/Vue/Angular/Svelte), template engines, and SSR/ISR - CSP/Trusted Types interactions, bypasses, and gadget-based execution 1. Identify sources (URL/query/hash/referrer, postMessage, storage, WebSocket, service worker messages, server JSON) and trace to sinks. 2. Classify sink context: HTML node, attribute, URL, script block, event handler, JavaScript eval-like, CSS, SVG foreignObject. 3. Determine current defenses: output encoding, sanitizer, CSP, Trusted Types, DOMPurify config, framework auto-escaping. 4. Craft minimal payloads per context; iterate with encoding/whitespace/casing/DOM mutation variants; confirm with observable side effects beyond alert. - Server render: templates (Jinja/EJS/Handlebars), SSR frameworks, email/PDF renderers - Client render: innerHTML/outerHTML/insertAdjacentHTML, template literals, dangerouslySetInnerHTML, v-html, $sce.trustAsHtml, Svelte {@html} - URL/DOM: location.hash/search, document.referrer, base href, data-* attributes - Events/handlers: onerror/onload/onfocus/onclick and JS: URL handlers - Cross-context: postMessage payloads, WebSocket messages, local/sessionStorage, IndexedDB - File/metadata: image/SVG/XML names and EXIF, office documents processed server/client - HTML text: encode < > & " ' - Attribute value: encode " ' < > & and ensure attribute quoted; avoid unquoted attributes - URL/JS URL: encode and validate scheme (allowlist https/mailto/tel); disallow javascript/data - JS string: escape quotes, backslashes, newlines; prefer JSON.stringify - CSS: avoid injecting into style; sanitize property names/values; beware url() and expression() - SVG/MathML: treat as active content; many tags execute via onload or animation events - Compare responses with/without payload; normalize by length/ETag/digest; observe DOM diffs with MutationObserver - Time-based userland probes: setTimeout gating to detect execution without visible UI - Repeat tests across REST, GraphQL, WebSocket, SSE, Service Workers, and background sync; protections diverge per channel - Sources: location.* (hash/search), document.referrer, postMessage, storage, service worker messages - Sinks: innerHTML/outerHTML/insertAdjacentHTML, document.write, setAttribute, setTimeout/setInterval with strings, eval/Function, new Worker with blob URLs - Example vulnerable pattern: {% raw %} const q = new URLSearchParams(location.search).get('q'); results.innerHTML = `
  • ${q}
  • `; {% endraw %} Exploit: {% raw %}?q={% endraw %}
    - Leverage parser repairs to morph safe-looking markup into executable code (e.g., noscript, malformed tags) - Payloads: {% raw %}