Is this 100% safe against XSS? If not, can you please provide example bad string text showing me why it is not.
<html>
<body>
<script>
<?php
$bad = "some bad string. please give example text that makes the below unsafe";
echo "var a = ".json_encode($bad).";";
echo "var b = ".json_encode(array($bad)).";";
?>
</script>
</body>
</html>
Thanks.
a
doesn't it? – chustar May 6 '11 at 15:24$bad
actually coming from? Not that it matters sincejson_encode
only creates valid JSON, which is "non-executable". – Kevin Peno May 6 '11 at 15:25json_encode
creates valid json – Neal May 6 '11 at 15:26