QuizNot attempted
Which line is unsafe?
1–4 to choose, Enter to submit
Show answer & explanation
Correct answers:
el.innerHTML = comment<div dangerouslySetInnerHTML={{ __html: comment }} />
innerHTMLanddangerouslySetInnerHTMLhand the string to the HTML parser, so a payload like<img src=x onerror=alert(1)>creates an element whose handler runs.- Not textContent: it sets a text node, markup is never parsed.
- Not JSX {comment}: React escapes the value and renders it as text.
- If you must render user or CMS HTML, sanitize it with DOMPurify first.