XSS and CSRF mitigation
This post will explain what XSS and CSRF attacks on web applications are and also what the best practices are to counter them. It will explain the mitigation techniques: Output escaping, “HttpOnly” cookie and CSRF-token. XSS and CSRF explained Most web applications that require login use a session cookie that contains the session identifier (and preferably nothing else). This identifier corresponds on the server side with a session object, stored in a central session store. It is used as a proof that you once entered your username/password correct in the session and should therefore be protected carefully. A malicious JavaScript may be executed on your site that “steals” the session cookie and posts it to the attackers website. The attacker will be receiving these session cookies and can start using the application, while being logged in as you. This is called “Cross Site Scripting” or XSS. “Cross Site Request Forgery” on the other hand exploits the behavior of automatically sending the session cookie on every request. It will do something on the logged in web application on your behalf, by cross-posting a form from the attackers website to the web application you are logged in to. In this scenario we protect ourselves against XSS with output escaping and “HttpOnly” cookies and against CSRF with a so-called “CSRF token”. ...