Stored XSS and DOM-based XSS are two common types of cross-site scripting (XSS) vulnerabilities that can pose serious security risks to web applications. While both involve injecting malicious code into a website, they differ in how the code is executed and the potential impact on users.
Stored XSS, also known as persistent XSS, occurs when an attacker injects malicious code that is permanently stored on the target server and served to users whenever they access a specific page or view a particular piece of content. This type of XSS vulnerability is particularly dangerous because it can affect multiple users who visit the compromised page or interact with the infected content. The injected code is typically stored in a database, file, or other data storage mechanism and is retrieved and displayed to users without proper sanitization or validation.
To illustrate, suppose a social media platform allows users to post comments on a public forum. If an attacker manages to inject malicious JavaScript code into a comment, it can be stored in the platform's database and displayed to all users who view that particular post. When unsuspecting users load the page, their browsers will execute the injected code, potentially leading to unauthorized actions, data theft, or further exploitation.
On the other hand, DOM-based XSS, also known as client-side XSS or type-0 XSS, occurs when an attacker manipulates the Document Object Model (DOM) of a web page to inject and execute malicious code. Unlike stored XSS, the injected code is not stored on the server but rather directly modifies the webpage's DOM, which is responsible for rendering the page's structure and content in the browser. This type of XSS vulnerability is typically triggered by user interactions or specific actions that cause the browser to execute the injected code.
For example, consider a web application that allows users to submit feedback forms. If the application fails to properly sanitize or validate user input, an attacker could inject JavaScript code that modifies the DOM and performs unauthorized actions when the user submits the form. This could include stealing sensitive information, redirecting the user to a malicious website, or performing actions on behalf of the user without their consent.
To summarize, the main difference between stored XSS and DOM-based XSS lies in how the malicious code is executed. Stored XSS involves injecting code that is permanently stored on the server and served to users, while DOM-based XSS manipulates the webpage's DOM to execute the injected code in the user's browser. Both types of XSS vulnerabilities can have severe consequences, compromising user data, and enabling further attacks.
Understanding the difference between stored XSS and DOM-based XSS is important for web application security professionals. By identifying and mitigating these vulnerabilities, organizations can protect their users from potential attacks and maintain the integrity of their web applications.
Other recent questions and answers regarding Cross-site scripting:
- How can a web developer mitigate XSS vulnerabilities?
- How does reflected XSS differ from stored XSS?
- What are the three main types of cross-site scripting (XSS) attacks?

