0

I am trying to find the right way to harden my Javascript against code injection attacks.

So, I created what I thought would be a successful code injection:

    document.getElementById("result").innerHTML = "hello <script> alert(0) <\/script> kuku";

Evaluating document.getElementById("result").innerHTML in debugger shows that it did go through:

"hello <script> alert(0) </script> kuku"

So how come there is no alert?

Irina Rapoport
  • 1,404
  • 1
  • 20
  • 37
  • What do you mean, "*it did go through*"? The script seems clearly to no have been evaluated. – Bergi May 18 '15 at 01:47

1 Answers1

2

Setting the .innerHTML to content that includes <script> blocks will never cause the code embedded to be evaluated. That's just how .innerHTML works.

Pointy
  • 405,095
  • 59
  • 585
  • 614