Stopping XSS and Injection: Encode, Parameterize, Contain
A practical guide to defeating XSS (CWE-79), SQL injection (CWE-89), and command injection with output encoding, parameterized queries, and CSP.
- Injection (A03:2021) is one root cause: untrusted data is executed as code instead of treated as data.
- Beat XSS with context-aware output encoding and framework auto-escaping; never build HTML from strings.
- Beat SQLi and command injection with parameterized queries and argument arrays, never string concatenation.
- Avoid innerHTML and dangerouslySetInnerHTML; if unavoidable, sanitize with a trusted library like DOMPurify.
- Content-Security-Policy is defense-in-depth, not a fix, it limits damage when an encoding bug slips through.
Guard what you build. Prove what you guard. This app needs JavaScript to run an audit; please enable it.