Reflected XSS and stored XSS are two types of cross-site scripting (XSS) vulnerabilities that can compromise the security of web applications. While they both involve injecting malicious code into a website, they differ in how the code is delivered and executed.
Reflected XSS, also known as non-persistent XSS, occurs when the injected code is embedded in a URL parameter or a form input field. The malicious code is then reflected back to the user's browser without being stored on the server. When the user visits a specially crafted link or submits a manipulated form, the injected code is executed in the context of the victim's browser. This can lead to various attacks, such as stealing sensitive information, session hijacking, or defacing the website.
For example, consider a vulnerable search functionality that echoes the user's input without proper sanitization. An attacker could construct a malicious URL like:
https://example.com/search?query=<script>alert('XSS')</script>
When a victim clicks on this link, the script tag and its payload are reflected back in the search results page, causing the alert to pop up in the victim's browser.
On the other hand, stored XSS, also known as persistent XSS, involves injecting malicious code that is permanently stored on the target server. This type of vulnerability arises when user-supplied data is stored in a database or a file and later retrieved and displayed on web pages without proper sanitization. The injected code is then served to every user who accesses the affected page, increasing the potential impact of the attack.
For instance, imagine a comment section on a blog where user comments are not properly sanitized. An attacker could post a comment containing malicious JavaScript code:
<script>document.cookie='session_id=123456';</script>
Whenever a user views the blog post, the script tag and its payload are rendered by the server, allowing the attacker to steal the victim's session cookie.
To summarize, the main difference between reflected XSS and stored XSS lies in how the malicious code is delivered and executed. Reflected XSS involves injecting code that is immediately reflected back to the user's browser, while stored XSS involves injecting code that is stored on the server and served to multiple users. Both types of XSS vulnerabilities can have severe consequences, compromising the confidentiality, integrity, and availability of web applications.
Other recent questions and answers regarding Examination review:
- What is the defense-in-depth approach to mitigating XSS attacks and why is it important to implement multiple layers of security controls?
- Explain the concept of tag name evasion in XSS attacks and how attackers exploit it.
- How does HTML escaping help in preventing XSS attacks? Are there any limitations to this technique?
- Why is it important to properly sanitize and validate user input to prevent XSS attacks?
- What are the different types of XSS attacks and how do they differ from each other?
- Describe the steps that developers can take to mitigate the risk of XSS vulnerabilities in web applications.
- What are the potential consequences of a successful XSS attack?
- How can Cross-Site Scripting via data and JavaScript URLs be exploited by attackers?
- Explain the concept of Stored XSS and how it differs from other types of XSS attacks.
- What is Cross-Site Scripting (XSS) and how does it pose a threat to web applications?
View more questions and answers in Examination review

