Lesson 31 of 55
javascriptSecurity – XSS, CSP & Input Sanitisation
11 mins
Course progress56%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 31 of 55
javascript11 mins
Keep these ideas in mind as you work through the lesson.
Common attacks:
innerHTML/eval.Mitigations:
textContent, createTextNode).eval, new Function, and string‑based setTimeout.<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; object-src 'none';">
import DOMPurify from 'dompurify';
const clean = DOMPurify.sanitize(userHtml);
document.getElementById('output').innerHTML = clean;