Skip to content

QuizNot attempted

Which line is unsafe?

comment comes from another user. Which lines can run an attacker's script?

Select all that apply.

1–4 to choose, Enter to submit
Show answer & explanation

Correct answers:

  • el.innerHTML = comment
  • <div dangerouslySetInnerHTML={{ __html: comment }} />
  • innerHTML and dangerouslySetInnerHTML hand 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.