InterviewSolution
| 1. |
What is XSS Attack? Different types of XSS Attack and how to prevent them. |
|
Answer» XSS Attack: XSS refers to client-side code injection attack where an attacker can execute malicious scripts by making use of unvalidated or unencoded user inputs in web applications. This malicious scripts may attempt to steal sensitive information from the user visiting the website. We need to prevent attack by filtering user inputs using blacklisting(not allowing users to input character sequences such as <, >, <script> ETC.). Different type of XSS attacks : Stored or Type 1 XSS attacks: Stored XSS attacks in which the supplied malicious input from the attacker is persisted and stored in the back-end database or repository. Whenever that content is retrieved and rendered to be displayed on the web page, the browser is completely unaware of it and it either executes the malicious JavaScript that comes from the database or renders the malicious HTML markup, instead of displaying it as text. The stored XSS will remain permanently in the database and will impact all users visiting the affected web page. Reflected or Type 2 XSS attacks: Reflected XSS attacks are the second type of XSS attack vector, in which the malicious XSS payload is not stored in the database table for persistence, but is still injected in some parameter of the web page that gets rendered back to the user. The browser, unaware of this CHANGE, simply either renders the injected malicious HTML or executes the injected malicious Javascript code, again RESULTING in the user's data being compromised. DOM-based or Type 0 XSS attacks: A DOCUMENT object model-based XSS is the third category of XSS attacks. Here, the XSS payload is not sent to the server, but due to implementation flaws and changing the state/DOM of the web page with the help of client-side JavaScript, an attacker paces the payload that gets picked up with the JavaScript responsible for manipulating the state of the web page. Prevention Methods: ✓ Output encoding: Escaping any character a user enters before displaying it. ✓ Filtering inputs using whitelisting: Only allow CHARACTERS (e.g, A–Z and 0–9) to be entered. ✓ Filtering inputs using blacklisting: Not allowing a user to enter character sequences such as <script> or even < and > characters. |
|