An example
For our example, our user enters the following text as the
body of their news article;
Noel... <script>alert(’Gotcha’);</script>
If our Web page did not HTML escape this input then when
a person were to read the posted article, the Javascript within
the <script> and </script> HTML tags would be
executed and an alert shown. While this example is harmless,
it is possible to execute very malicious Javascript in this
way such as ‘cookie theft’ and ‘session
hijacking’. When HTML escaping is used however, the
news article would be displayed as it should be because the
HTML tags present would be re-written like so:
Noel... <script&rt;alert(’Gotcha’);</script>
Meaning that they are now harmless text and not interpreted
as HTML by the user’s Web browser.
|