Cross Site Scripting (XSS) Attack Types & Prevention

Back to Blog

Cross Site Scripting (XSS) Attack Types & Prevention


Cross-Site Scripting(XSS) is a popular and vulnerable attack that is known by every advanced tester. It is considered one of the adventurous attacks on web applications and can bring harmful results also. This attack is considered adventurous, because of its ability to damage even less vulnerable technologies.

How XSS is Being Performed:

A cross-site Scripting attack means sending and injecting malicious script or code. Javascript and HTML are mostly used to perform this attack, the main reason for such type of attack is inappropriate user input validation. A malicious user can enter scripts, which will be injected into the website’s code then the browser is not able to identify if the executed code is malicious or not.

The Common Cause of XSS:

  • Cross-Site Scripting can occur on the client side by executing malicious scripts.
  • The fake page or form or advertisement is displayed to the users (where the victim types credentials or clicks a malicious link).
  • Malicious emails are sent to the victim with malicious links.


If the below search field is vulnerable then the user can enter any script and it will be executed.

For example, consider the user enters a very simple script as shown below:



As in this Example, the script typed into the search field gets executed. This just shows the

vulnerability of the XSS attack. However, a more harmful script may be typed as well.

Types of Cross-Site Scripting Attacks:

This attack is divided into three main categories which are shown below:

1) Reflected XSS – This attack occurs when malicious scripts are not being saved on the web server but reflected in the website’s results.

2) Stored XSS – This attack occurs when malicious scripts are being saved on the web server permanently.

3) DOM – This occurs, when the DOM environment is being changed without any actual change in DOM itself.

Recommended to Read- Top Test Automation Tools

How to Test Against XSS?

In order to test against XSS attacks, black box testing can be performed. That means it can be tested without a code review. However, code review is always a recommended practice and it brings up more credible results. From our testing experience, We would like to add that if a good black box testing technique is selected and performed accurately, then we will also be able to identify maximum vulnerabilities.

For Example, a tester may try to type in the browser script

Like: <script>alert(document.cookie)</script>


If this script is being executed, then there is a huge possibility that means XSS is possible. Also while testing manually for possible Cross-Site Scripting attacks, it is important to remember, that encoded brackets should also be tried.

XSS Testing Tools:

As Cross Site Scripting test attack is one of the most popular risky attacks, there are many anti-XSS tools to test it automatically. We can find various scanners to check for possible XSS attack vulnerabilities – like, Nessus and Nikto. Both of which are considered quite reliable.

From our experience, we would like to recommend ZAP (Zed Attack Proxy) tool.

Comparison with Other Attacks:

XSS is considered to be one of the risky attacks, as its main purpose is to hack the website’s or system’s user identities. Also, the XSS attack can be performed with different client-side languages like Javascript, HTML, VBScript, Flash, etc. and this makes it more noxious and widespread than the other possible attacks.

Another thing that makes this attack risky is the possibility to be stored in the web service – this way it can affect many users for a longer period of time. XSS sometimes can be performed on even less vulnerable systems and its vulnerabilities are sometimes difficult to be found.

Ways to Prevent XSS:

Though such a type of attack is considered to be one of the most dangerous and risky ones, so prevention plan should be prepared. Because of the popularity of this attack, there are many ways to prevent it.

Commonly used prevention methods include:

  • Data validation
  • Filtering
  • Escaping

XSS Cheat Sheets

XSS Cheat Sheets can be very useful for cross-site scripting prevention. It is a simple guideline for the developers on how to prevent XSS attacks. The rules are very helpful and should not be forgotten while developing the application. XSS Cheat Sheets can be found in internet communities such as OWASP (The Open Web Application Security Project).


While testing, it is highly recommended to evaluate the risks that bring up possible XSS attacks. XSS attacks can affect many web applications that seem to be secure as well. While performing tests against XSS, it is important to have a good understanding of this attack. It is important to choose the appropriate anti-XSS testing tools and to analyze testing results correctly.

  • What are anti-XSS tools?

Anti-XSS (Cross-Site Scripting) tools are software or services that help protect websites and web applications from XSS attacks. These tools can include web application firewalls, input validation libraries, and other security measures that are designed to prevent malicious code from being injected into a website.

  • What are the different types of XSS attacks?

There are three main types of XSS attacks:

  1. Reflected XSS
  2. Stored XSS
  3. DOM-based XSS
  • What is an XSS test string?

An XSS test string is a piece of code that is used to test for vulnerabilities to XSS attacks. These test strings are typically harmless but can help identify potential vulnerabilities in a website or web application.

  • What is an XSS testing tool?

An XSS testing tool is a software or service that is used to test a website or web application for vulnerabilities to XSS attacks. These tools can help identify potential weaknesses in the website’s security and can be used to test the effectiveness of anti-XSS measures.

  • How can I test my website for cross-site scripting vulnerabilities?

It is important to note that testing for XSS vulnerabilities is just one aspect of website security, and it is recommended to have a comprehensive security strategy in place to protect against a variety of threats.

Share this post

Back to Blog