Browser & Web Performance · Senior · Question 53 of 75

What is the danger of injecting server data into an inline script like this?

<script>
  window.__STATE__ = ${JSON.stringify(state)};
</script>

Explanation

Escape < as \u003c when embedding JSON in HTML, or put data in a type="application/json" script and parse it.

Further reading

Problem with a question

Browser & Web Performance · Senior · question 53

Test yourself

Take the Browser & Web Performance · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz