Open In App

Reflected XSS Vulnerability in Depth

In this article, we will discuss one of the most seen vulnerabilities in web-based applications, which is — Reflected XSS.

What is Cross-Site Scripting:



Types of Cross-Site Scripting:

Reflected XSS in Depth:



Steps of Reflected XSS


 

In the above figure:

Example 1: Consider a web application that takes search string from the user via the search parameter provided on the query string.

http://target.com/aform.html?search=Gaurav

The application server wants to show the search value which is provided by the user on the HTML page. In this case, PHP is used to pull the value from the URL and generate the result HTML

<?php echo ‘You Searched: ‘ . $_GET[“search”]; ?>

Check how the input provided by the user in the URL is directly passed forward with no input validation performed and no output encoding in place. A malicious script thus can be formed such that if a victim clicks on the URL, a malicious script would then be executed by the victim’s browser and send the session values to the attacker. 

http://target.com/aform.html?search=<script>alert(‘XSS by Gaurav’);</script>

 

Example 2: Reflected XSS can also occur when an application employs a dynamic page to display error messages to users. Basically, the page takes an input parameter containing the message’s text and simply displays this text back to the user within the response. 
Consider the following URL, which returns the error message

http://target.com/error/5/Error.ashx?message=Sorry%2c+an+error+occurred

If we check the HTML source for the returned page, the application simply copies the value of the message parameter in the URL and inserts it into the error page at a suitable place.

<p>Sorry, an error occurred.</p>

As there is no sanitization and validation performed for the error message attacker can easily insert the malicious script which generates a pop-up dialog.

http://target.com/error/5/Error.ashx?message=<script>alert(“XSS by GAURAV”)</script>

Requesting this link generates an HTML response page that contains the following in place of the original message.

<p><script>alert(“XSS by GAURAV”);</script></p>

Mitigations:

Impact of Reflected XSS:

Article Tags :