Prevent Cross-Site Scripting

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • hard
  • Pro

A comments section builds its HTML by joining strings that include each comment's text, then sets it with innerHTML. A user posts a comment containing a script that steals other visitors' data. Explain how the attack works and how you'd defend against it.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →