Web Security · Middle · Question 1 of 75

A value is HTML-escaped and then placed into an inline script: <script>var q = '{{value}}';</script>. Why is this still unsafe?

Explanation

Each context has its own escaping rules. The safest option is to avoid it: put data in a data- attribute or a JSON block and read it from your script.

Further reading

Problem with a question

Web Security · Middle · question 1

Test yourself

Take the Web Security · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz