QuizNot attempted
XSS
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
element.textContent = comment
textContentcreates a text node and never parses HTML, so markup in the comment is shown literally.- Not innerHTML: parses the string, so
<img onerror>payloads run. - Not document.write: writes raw HTML into the document (and blows it away after load).
- Not outerHTML: parses HTML just like innerHTML.
- If you must render HTML, sanitise it (DOMPurify) and add a CSP.