Fixing DOM XSS
The Document Object Model (DOM) is an object interface that represents an HTML page. This interface allows client-side scripts to manipulate, add or remove elements from the document. The client-side script used in conjunction with the JavaScript programming language can be written insecurely and opens up security vulnerabilities such as DOM-based XSS.
DOM XSS, in contrast to reflected and stored XSS, is not a server-side exploit. The weakness is in the client-side code when it attempts to modify the DOM to display data, but instead interprets the input into code due to a lack of encoding and proper escaping. In this recipe, we will fix the DOM-based XSS vulnerability by using an encoding function from a JavaScript library.
Let's now see in action how a DOM XSS vulnerability can be tested.
Testing DOM XSS
Here are the steps:
- Navigate to Terminal | New Terminal in the menu or simply press Ctrl + Shift + ' in Visual Studio Code.
- Type...