3 ms·
While XSS can be a real problem for the users of your site (viral effects like the samy worm, phishing, session hijacking, session fixation, and more) what you'
by EGreg 16y ago
While XSS can be a real problem for the users of your site (viral effects like the samy worm, phishing, session hijacking, session fixation, and more) what you've been able to do there is basically take advantage of another vulnerability -- namely an open vector of attack which allows people to upload executable PHP scripts to the server. Technically, you didn't have to do much scripting, you simply had to upload a file to the server, taking advantage of the vulnerability.
That said, how do you protect against XSS? The simple way is to only include your own .js files, and only print json-encoded data in the page. In PHP, it would look something like:
<script type="text/javascript"><!--
var MyAppData = <?php echo htmlentities(json_encode($app_data), 'utf-8'); ?>
//--></script>
But what if you want to go further and actually allow the server to echo scripts? How do you make sure several scripts from various "modules" can coexist on one page?
Facebook did it by parsing and sanitizing javascript into FBJS, however in the process they made it incompatible with the usual DOM methods, etc. Google released CAJA, which is cooler IMHO since it jives better with Javascript. Finally, you can disallow scripting completely and use iframes -- however, the iframes are dangerous in one way: they may "bust out" of your page by changing top.location . Does anyone know how to prevent this?