Let's say I have something like this:
<script>
var string = '<?= $_GET['var'] ?>';
</script>
To prevent XSS I'd want to make sure the single quotes are escaped. addslashes
could do that but people could still break out of that by setting $_GET['var']
to . eg.
<script>
var string = '</script><script>alert(/test/)</script>';
</script>
Maybe I should escape (with \
) single quotes and <
? Is that all I'd need to escape?
I suppose attacks like this are harder now that browsers often disable code from being ran that shows up in the GET string but idk I still think it's something that ought to be protected against .