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:
https://www.example.beaglesecurity.com/page.html?default=France
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.
The Javascript code present in a page doesn’t expect the default parameter to contain HTML markup. The script merely echoes the HTML tag into the page (DOM) at runtime. The browser then renders the page and executes the attacker’s script.
Using this vulnerability, an attacker can:-
Beagle recommends the following fixes:-