Cross-Site Scripting:  Why is it Still So Prevalent?

Posted by Joe Basirico on September 16, 2011 at 10:43 AM
Find me on:

As a security researcher, I regularly come across software applications that are susceptible to a few basic types of attacks – and I struggle to understand how these can continue to slip through each phase of development and into production. There are a handful of vulnerabilities that fit into this group; cross-site scripting (XSS) being one of them – and we find them in just about every application we test.

A Cross Site Scripting vulnerability allows an attacker to modify a web page however they see fit, sometimes by injecting JavaScript, flash objects, HTML or anything else the browser can render. Because the payload is delivered by a vulnerable site, XSS will prey on a user’s trust relationship with the website they are visiting – and the browser has no way of discerning if the code was created by the original developer or a malicious attacker.

Anything that can render HTML or includes a web interface is potentially vulnerable including mobile devices and desktop applications.  When the script is stored in a database it becomes persistent, which is far worse because the same attack can be used for any user that browses to the site.

Below are common mistakes that organizations make that leave their applications vulnerable to attack. Be sure they don’t exist in yours.

  • Failure to use whitelist validation before it is processed by the application.
  • Trusting data retrieved from any database or other data source
  • Failing to encode any remotely provided data, including reverse DNS lookup, cookie contents, uploaded files, etc.
  • Improperly converting "safe" tags to HTML.
  • Displaying user input directly without encoding it appropriately for the context in which it is used.
  • Checking user submitted data against a blacklist instead of a whitelist.

In my next blog entry, I’ll talk about how to properly use Input validation to prevent XSS flaws.

Topics: developer guidance, application security

Joe Basirico

Written by Joe Basirico