Information Security Stack Exchange is a question and answer site for information security professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If you have an HTML file that contains the following code :

   <!doctype html>
    <html lang="en">
        <meta charset="UTF-8">
        <script type="text/javascript">
            var a = '</script><script>alert("xss")</script>'

when opening it in a browser, it will incorectly (?) alert "xss".

  • Is this normal behaviour for browsers (in my case the latest Chrome) to interpret JavaScript strings as being valid tags ?
share|improve this question
up vote 3 down vote accepted

Yes it's normal.

HTML is parsed first, then JavaScript. So, after encountering a <script> start tag, the browser will look for the closing </script> tag. When that's found, the collected string will be parsed as a script if the type (usually and defaults to JavaScript) is recognizned.

If you use the DOM inspector (F12, or right-click -> Inspect Element), then you'll see the following tree. In the JavaScript console, you'll also see that a script error has occurred (the first string is not terminated).

The third </script> tag is not visible in the screenshot, because the DOM parser did not find a corresponding start tag. So it's omitted.

share|improve this answer
thanks for the quick answer ! – Awake Zoldiek Dec 30 '13 at 23:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.