Zum Inhalt springen
uencoder

XSS Prevention Referenz

Referenz für Cross-Site Scripting prevention: Kodierung, CSP, sanitization, und trusted Typen.

XSS Types

Reflected XSS injects script via query parameters reflected in the response. Stored XSS persists payload in the database, affecting all viewers. DOM XSS manipulates client-side DOM without server involvement (source-to-sink data flow). Mutation XSS exploits browser HTML parsing quirks to bypass sanitization. All types execute attacker JavaScript in the victim's context, enabling session theft, credential exfiltration, and actions on behalf of the user.

reflected
Query param injection
non-persistent
stored
Database persistence
affects all users
DOM
Client-side only
no server roundtrip

Prevention Techniques

Context-aware output encoding is the primary defense: HTML-encode for HTML context, attribute-encode for attributes, JS-encode for script, URL-encode for URLs. CSP with nonces or hashes provides defense in depth. DOMPurify sanitizes HTML for rich text. Trusted Types (browser API) enforce type-safe DOM sink access, preventing DOM XSS. Avoid innerHTML; use textContent or createElement. Frameworks (React, Angular) auto-encode by default but have escape hatches that need care.

encoding
Context-aware
primary defense
CSP
Defense in depth
nonce/hash
Trusted Types
Type-safe sinks
DOM XSS prevention

Verwandte Tools

参考链接