System Design · Junior · Question 43 of 75
How do you protect against XSS when displaying user content?
- ✓Correct answer: Escape output, never insert HTML without sanitizing, configure CSP
- 2Check that the user typed the text in English
- 3Store user content only in
localStorage
Explanation
Frameworks escape text by default; the dangerous parts are innerHTML, dangerouslySetInnerHTML and javascript: links. If HTML is needed (an editor), it's sanitized on the server and the client. CSP restricts script sources - a second line of defense.