NA
NA
Reflected XSS
Stored XSS
DOM-Based XSS
Reflected XSS:
Reflected XSS arises when an attacker injects the malicious script into the web
application, and the server immediately reflects the response back to the request
without validating or sanitizing user input.
This attack reflected off the web server, such as in a search result or error
message.
It’s a client-side attack that is carried out through a single request/response
cycle; hence it can be referred to as non-persistent XSS.
, <script>alert(1)</script>
Scenario: A social media website that allows users to share links. An attacker
creates a malicious link including JavaScript code.
Instagram.com/share?url=<script>alert(‘1’)</script>Impact: When the user clicks on
the link, the website displays the link in the user’s feed. And the browser
executes the injected script and displays an alert box.
How to Prevent Reflected XSS:
Stored XSS:
Stored XSS is a high-severity XSS vulnerability due to its impact. In this attack,
the attacker injects a malicious script into the web application, and that script
will be stored permanently on the server, so whenever the users of the website load
the affected page, the XSS will be triggered and display the stored data to each
and every user.
It comes under the persistent because once the payload is stored in the server, it
will reflect ‘alert’ everyone who is trying to access the affected webpage.
This attack has a wider reach because it can be triggered for everyone, even if
they don’t have any kind of interaction with the attacker.
Scenario: A website allows users to post feedback. An attacker injects malicious
Javascript into a comment:
<script>document.cookie = document.cookie;</script>
Impact : after stored this script on server , is displayed to all users who view
post. Their browsers will execute the script, potentially stealing their session
cookies.
Preventions:
Proper input sanitization and validation are required before storing any data in
the server database.
Implement the content security policy to restrict the source from page load
scripts.
DOM-Based XSS:
DOM-based XSS occurs when an attacker is able to manipulate the DOM of a web page
in a way that allows them to execute malicious scripts. Unlike traditional XSS,
which often relies on server-side vulnerabilities,
DOM-based XSS is entirely client-side. This means that the attack is executed in
the user's browser, making it particularly challenging to detect and mitigate.
Preventions:
Check and clean the user input before processing any request on it.
Use CSP policy to restrict or block the dangerous scripts.
Use safe methods instead of inserting the raw data, like with innerHTML, and use
safer methods like textContent that block scripts before execution.