Cross-Site Scripting (XSS) is a client-side code injection attack where an attacker can execute malicious scripts into a website or web application. Document Object Model based Cross Site Scripting is a type of Cross Site Scripting attack. This attack is encountered when a web application’s client-side scripts write user-provided information to the Document Object Model. The data is read using the Document Object Model. It is then outputted to the browser. If the information is incorrectly handled, an attacker can inject a payload as part of the Document Object Model. The payload is executed when the data is read as a response from the Document Object Model.
If a web application is found that allows Document Object Model-Based Cross Site Scripting, the application’s Document Object Model might contain several vulnerable files that the attacker can manipulate in order to generate the Cross Site Scripting conditions.
The following code is used to creating a form to let the user choose his/her country.
The page is requested with the below URL:
A DOM-Based XSS can be against this page can be perforated by an attacker by sending the following URL to a victim:-
The above URL will alert the cookie.
Using this vulnerability, an attacker can:-
Beagle recommends the following fixes:-