Cross site scripting exploits insert a client side script. Code that can be run in a browser. Java script
is a well know client side scripting language. one common method is to include the script is a PHP.
example:
http://www.SOMEDOMAIN.com/index.php?cPath=<script>alert('hello')</script>
problem:
cPath=<script>alert('hello')</script>
on the server side you would usually get the cPath by using a get
$cpath=$_GET['cPath'];
Because
getcre.com does not filter this, it is possible the script
<script>alert('hello')</script> will be passed back to the browser of the person viewing the page and be run.
In order to break the cross site scripting, all variables should be filtered input. There is usually three types of data handle variables:
integer and integers with a floating decimal point. If we know the data will be a whole number we can type class the data.
$product_id= (int)$_GET['product_id']; This turns any text like <script>alert('hello')</script> into number that can be translated back and make
any since at all.
For text inupts we can replace certain key symbols so the script won't work in a browser. For browsers to
actually run the client side script there must be script tags. <script> and </script>
By using
tep_db_prepare_input we can filter the string to remove the critical items for the script to run. It will work with data that is an array to just a string.
$cpath = tep_db_prepare_input($_GET['cPath']);it becomes:
-script-alert('hello')-/script- which will never run in a browser unless there is a bug in the browser code.
it also clean any + signs from the input like this java script code line:
error_message = error_message + "* " + message + "\n";is changed to:
error_message = error_message "* " message "\n";Again this will not run in a browser since it has no + to join the string.
By filtering all data fields by type classing, or tep function we are breaking the cross site script so
it won't run. So when you do see vulnerability reports from ecommerce security blogs and websites that input validation is need, check to see if it has proper filtering on those variables