Since TextArea ( <textarea>...</textarea> ) is a node that can have internal nodes in it. Internal nodes are still valid, so the browser interprets the script node and runs the code.
This is a really good reason why you should always check that the user enters and sends to the server. If you print this input later, it can run just as you would like to insert a script tag yourself.
To stop it, you need to encode the tags < = < and > = > < = < and > = >
A similar concept has nodes that are not valid html, for example <myInvalidTag><script></script></myInvalidTag> . The browser will still execute code inside it.
source share