Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications which can be used by an attacker to compromise the same origin policy of client-side scripting languages.
The term cross-site scripting is not a very accurate description of this class of vulnerability. In the words of XSS pioneer Marc Slemko:
This issue isn't just about scripting, and there isn't necessarily anything cross-site about it. So why the name? It was coined earlier on when the problem was less understood, and it stuck. Believe me, we have had more important things to do than think of a better name.
The acronym CSS was often used in the early days to refer to cross-site scripting vulnerabilities, but this quickly became confusing in technical circles because both Cascading Style Sheets and the Content-scrambling system shared the same acronym. Perhaps the first use of the abbreviation XSS was by Steve Champeon in his Webmonkey article "XSS, Trust, and Barney". In 2002, Steve also posted the suggestion of using XSS as an alternative abbreviation to the Bugtraq mailing list. In a rare show of unity, the security community quickly adopted the alternative, and CSS is rarely used today to refer to cross-site scripting.
Since then, other similar access control policies have been adopted in other browsers and client-side scripting languages to protect users from malicious websites. In general, cross-site scripting holes can be seen as vulnerabilities which allow attackers to bypass these mechanisms. By finding clever ways of injecting malicious script into pages served by other domains, an attacker can gain elevated privilege to sensitive page content, session cookies, and a variety of other objects.
In practice, exploiting such a hole would be very similar to the exploit of Type 1 vulnerabilities (see below), except in one very important situation. Because of the way Internet Explorer treats client-side script in objects located in the "local zone" (for instance, on the client's local hard drive), a XSS hole of this kind in a local page can result in remote execution vulnerabilities. For example, if an attacker hosts a malicious website, which contains a link to a vulnerable page on a client's local system, a script could be injected and would run with privileges of that user's browser on their system. This bypasses the entire client-side sandbox, not just the cross-domain restrictions that are normally bypassed with XSS exploits.
At first blush, this doesn't appear to be a serious problem since users can only inject code into their own pages. However, with a small amount of social engineering, an attacker could convince a user to follow a malicious URL which injects code into the results page, giving the attacker full access to that page's content. Due to the general requirement of the use of some social engineering in this case (and normally in Type 0 vulnerabilities as well), many programmers have disregarded these holes as not terribly important. This misconception is sometimes applied to XSS holes in general (even though this is only one type of XSS) and there is often disagreement in the security community as to the importance of cross-site scripting vulnerabilities.
Type-0 attack
Type-1 attack
Type-2 attack
Please note, the preceding examples are merely a representation of common methods of exploit and are not meant to encompass all vectors of attack.
An example of a type-0 vulnerability was once found in an error page produced by Bugzilla where JavaScript was used to write the current URL, through the document.location variable, to the page without any filtering or encoding. In this case, an attacker who controlled the URL might have been able to inject script, depending on the behavior of the browser in use. This vulnerability was fixed by encoding the special characters in the document.location string prior to writing it to the page.
A recent type-1 vulnerability can be found in older versions of ATutor, an Open Source Web-based Learning Content Management System (LCMS) written in PHP. This vulnerability exists in the application's site search page. Script could be injected into nearly every URL request parameter, and the result page would include the malicious script.
Finally, an example of a type 2 vulnerability was found in Hotmail, in October of 2001 by Marc Slemko, which allowed an attacker to steal a user's Microsoft .NET Passport session cookies. The exploit for this vulnerability consisted of sending a malicious email to a Hotmail user, which contained malformed HTML. The script filtering code in Hotmail's site failed to remove the broken HTML and Internet Explorer's parsing algorithm happily interpreted the malicious code. This problem was quickly fixed, but multiple similar problems were found in Hotmail and other Passport sites later on.
A similar example, which was more fatal, was found in Indiatimes Email portal by Sandeep Giri. This example demonstrated that if a mailing service is vulnerable to such kind of attack a victim's inbox can be hijacked even if victim doesn't open the mail sent by malicious user.
On October 13, 2005 Samy exploited a security flaw in MySpace resulting in over one million friend requests being made to its creators profile. Qualifying as a type 2 vulnerability, it used multiple XMLHttpRequests to propogate itself.
Netcraft announced on June 16, 2006. A security flaw in the PayPal web site is being actively exploited by fraudsters to steal credit card numbers and other personal information belonging to PayPal users. The issue was reported to Netcraft via their own anti-phishing toolbar. Soon after, Paypal reported that a "change in some of the code" on the Paypal website had removed the vulnerability.
An example of this kind of quoting is shown below, from within the Python interpreter:
~> python Python 2.3.5 (#2, Aug 30 2005, 15:50:26) Type "help", "copyright", "credits" or "license" for more information. >>> import cgi>>> print ""
>>> print cgi.escape(""); <script>alert('xss');</script>
Here, the first print statement produces executable client-side script, whereas the second print statement outputs a string which is an HTML-quoted version of the original script. The quoted versions of these characters will appear as literals in a browser, rather than with their special meaning as HTML tags. This prevents any script from being injected into HTML output, but it also prevents any user-supplied input from being formatted with benign HTML.
The ultimate problem with trying to avoid XSS vulnerabilities is that every situation is different. For any given situation, the needs and the issues change. For instance, if user input is going into the src attribute of a hyperlink, cgi.escape() would not be sufficient. Let's say a picture was to be added to a page of pictures, in this fashion:
An attacker could enter "doesntexist.jpg' onerror='alert(document.cookie)" to add an event which triggers when the browser fails to load "doesntexist.jpg", executing the code. If one were to implement a function like cgi.escape() (which comes with Python), one would be best off converting all but known-safe characters to their equivalent HTML entity. Because browsers implement complex (and often buggy) parsing algorithms for HTML (in all of its flavors), it is difficult to predict what characters could be treated as special. In particular, support for Unicode character sets by browsers could leave an application open to XSS attacks if the HTML quoting algorithms only look for known-bad characters.
As stated above, the unfortunate consequence of this fix is that users are prevented from embedding non-malicious HTML into pages. Because HTML standards do not provide any simple mechanism to disable client-side scripts in specific portions of a web-page, it is difficult to reliably cleanse script from normal HTML. The most reliable method is for web applications to parse the HTML, strip tags and attributes that don't appear in a whitelist, and output valid HTML.
Besides content filtering, other methods for XSS mitigation are also commonly used. One example is that of cookie security. Many web applications rely on session cookies for authentication between individual HTTP requests, and because client-side scripts generally have access to these cookies, most simple XSS exploits are written to steal these cookies. To mitigate this particular threat (though not the XSS problem in general), many web applications tie session cookies to the IP address of the user who originally logged in, and only permit that IP to use that cookie. This is effective in most situations (if an attacker is only after the cookie), but obviously breaks down in situations where an attacker is behind the same NATed IP address or web proxy. Internet Explorer also has a feature, called the HTTP Only flag, which allows a webserver to set a cookie which is unavailable to client-side scripts. While this seems like a useful feature, it does not prevent the use of XSS to steal passwords or perform cross-site request forgery attacks.
An additional common mitigation, is to use input validation of all potentially malicious data sources. This is a common theme in application development (even outside of web development) and is generally very useful. For instance, if a form accepts some field, which is supposed to contain a phone number, a server-side routine could validate that the input fit a very specific format (eg "(555) 555-5555"), which eliminates the possibility that it contains any client-side script. (Incidentally, this can be used to prevent other injection attacks, such as SQL injection, from being successful.) While effective for most types of input, there are times when an application, by design, must be able to accept special HTML characters, such as '<' and '>'. In these situations, HTML entity encoding is the only option.
Finally, some web applications are written to operate completely without the need for client-side scripts. This allows users, if they choose, to completely disable scripting in their browsers before using the application. In this way, even potentially malicious HTML can be displayed unencoded on a page, and users will not be susceptible to XSS attacks. Many browsers can be configured to disable client-side scripts on a per-domain basis, which greatly enhances the convenience of such a system. The major drawback to this mitigation is that most users are ignorant of such measures, and would not know how to properly secure their browsers for such applications.
Cross-Site Scripting | XSS | XSS | Cross site scripting | Cross-site scripting | クロスサイトスクリプティング | Cross Site Scripting | Cross Site Scripting | XSS | Cross site scripting
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Cross-site scripting".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world