Cross-Site Request Forgery (CSRF)

Cross-Site Request Forgery (CSRF) is a type of attack where an attacker tricks a victim into performing an unwanted action on a web application while the victim is authenticated. The attack exploits the trust between the web application and the victim's browser to execute unauthorized requests.

The process of a CSRF attack typically involves the following steps:

  1. Victim Authentication: The victim logs into a web application, which generates a session and sets a session cookie in the victim's browser.
  2. Malicious Request Preparation: The attacker crafts a malicious webpage or email that contains a request to the target web application. This request is designed to perform an undesired action on behalf of the victim.
  3. Victim Interaction: The victim visits the malicious webpage or clicks on a malicious link in the email, which triggers the browser to automatically send the request to the target web application.
  4. Unauthorized Action: The target web application, assuming the request is legitimate due to the victim's authentication, processes the forged request and performs the unintended action, such as updating account settings or making a financial transaction.

To mitigate the risks associated with CSRF attacks, the following preventive measures can be implemented: