Is it possible to inject XSS in a JavaScript variable if a website inserts HTML encoded, user input in a double quoted string?
var userString = "perfectly "safe" input from user?";
Information Security Stack Exchange is a question and answer site for information security professionals. It only takes a minute to sign up.
Sign up to join this communityIs it possible to inject XSS in a JavaScript variable if a website inserts HTML encoded, user input in a double quoted string?
var userString = "perfectly "safe" input from user?";
It is probably not possible to get XSS given this simple character restriction. However, an attacker could inject an escape character, for example:
var userString = "perfectly "safe" input from user?\"+"+alert(1);
In this case the attacker would be injecting a \
and an alert(1)
in two different variables which existing in two locations within the <script>
tag. Escape characters are a type of control character that are commonly forgotten by developers when sanitizing attacker controlled data.
... also hopefully you took this into consideration:
<script>
var userString = "</script><script>alert(1)//"
</script>
"
is encoded into "
, I hope <
and >
are too!
< & >
, but good to know for completeness.
Jun 27, 2013 at 2:59
&#xhhhh;
supports all of ASCII and even Unicode! However, you did not mention what HTML encode function you used.