Cross Site Scripting (XSS) attacks are a type of injection attack. XSS is probably the most common type of malicious attack after code injection. They are certainly the most common vulnerability type targeting client browsers and web views.
Web servers deliver both static and dynamic content to client browsers. The dynamic content includes scripts that are executed on the client. These scripts can come from various sources when a dynamic web page is being delivered and displayed by a web browser on a client device. If an attacker manages to inject their own scripts into the dynamic pages delivered from servers, then the client will execute the scripts. This can lead to various unauthorised activities such as data being redirected, user accounts being compromised, cookies being downloaded for analysis, or the deployment of malware or other unauthorised software. The type of activity that could be performed when malicious scripts are executed is almost limitless. If a script written in JavaScript or one of the other client side scripting languages can be inserted into a web page being viewed by an authenticated user, then that malicious code could have ready access to other applications and data on the client and connected servers. Any data or process that is available to the web browser could be compromised. The client web viewer that is compromised in an XSS attack does not have to be a standard web browser. It could also be an embedded web view in an application.
Cross site scripting attacks have traditionally been organised into three types. There is some overlap between the types due to the way that the scripts are delivered. The traditional types are:
Starting in 2012 there has been an effort to reclassify the types of XSS attacks under two main headings. These are:
The definition of DOM Based XSS doesn’t change under these two new definitions. DOM Based XSS is simply a subset of Client XSS, where the source of the data is somewhere in the DOM, rather than from the Server.
Given that both Server XSS and Client XSS can be Stored or Reflected, this new classification results in a simple matrix with Client & Server XSS on one axis, and Stored and Reflected XSS on the other as shown in table below:
Server XSS is caused by allowing untrusted data to be inserted into dynamic web pages sent from servers to client browsers. The easiest and strongest defence against Server XSS in most cases is to enable context-sensitive server side output encoding. Details on how to implement this, and many other ways to counter XSS attacks are presented in detail in the OWASP XSS (Cross Site Scripting) Prevention Cheat Sheet.
Client XSS is often caused when untrusted data is used to update the DOM with an unsafe JavaScript call. The easiest and strongest defence against this is to only allow the use of safe and trusted JavaScript APIs. Addition information on preventing Client XSS attacks is given in the cheat sheet link in the previous paragraph. A dedicated OWASP DOM based XSS Prevention Cheat Sheet is also available.
As stated in other articles in this series it’s also vital that systems are kept up to date with the latest software versions. Security vulnerabilities and bugs are constantly being discovered and fixed. General network security infrastructure should be kept up to date as well. Firewalls, content checkers, anti-malware systems and Load Balancers should be running the latest software patches. Additional security tools should also be deployed and kept up to date. The KEMP Web Application Firewall Pack (AFP) for LoadMaster includes tools that continuously monitor traffic to application and web servers. It detects and counters known vulnerabilities, including those outlined in the OWASP top 10. Specifically it detects and prevents the malicious injection of untrusted data into values that are passed between servers and clients. The AFP pack is updated constantly by KEMP security experts so that vulnerabilities developers and system administrators may not have heard about are countered.