3 ms·
I think the fixed code here is vulnerable to a subtle XSS. <?php $serverVars = [ 'injectMe' => (string)$_GET['injectme'] ]; ?> <scrip
by simonw 9y ago
I think the fixed code here is vulnerable to a subtle XSS.
<?php
$serverVars = [
'injectMe' => (string)$_GET['injectme']
];
?>
<script>
window.SERVER_VARS = <?= json_encode($serverVars) ?>
The problem here is that the injectme parameter could include a closing </script> tag to escape that script block. Something like this:
?injectme=</script><script>alert('xss')</script>
The fix for this exploit is to endure any < or > characters in the JSON are escaped using JSON character encoding. I think this is the correct recipe for that in PHP:
json_encode($a, JSON_HEX_TAG)
- deleted 9y ago[deleted]
- deleted 9y ago[deleted]
- megous 9y agojson_encode will escape / with \ by default, so this shouldn't be an issue.