What is CSRF (Cross Site Request Forgery)?
Cross-site request forgery (CSRF) is a technique that enables attackers to impersonate a legitimate, trusted user. CSRF attacks can be used to change firewall settings, post malicious data to forums, or conduct fraudulent transactions. In many cases, affected users and website owners are unaware that an attack occurred, and become aware of it only after the damage is done and recovery is not possible.
CSRF attacks exploit a mechanism that makes the sign-in process more convenient. Browsers often automatically include credentials in the request when a user tries to access a site. These credentials can include the user’s session cookies, basic authentication credentials, IP address, and Windows domain credentials.
If there is no protection against CSRF attacks, it can be easy for an attacker to hijack the session and impersonate the user. Once a user is authenticated on the site, the site cannot differentiate between a legitimate user request and a fake request sent by the attacker.
In this article:
CSRF Attack Examples
1. Bank Transfer Using GET or POST
Consider a user who wants to transfer an amount of $5,000 to a family member via the web application of Acme Bank, which has a CSRF vulnerability. An attacker identifies this vulnerability and wants to intercept this transaction so that the funds are transferred to their bank account instead of to the intended recipient.
The attacker can construct two types of URLs to perform the illicit funds transfer, depending on whether the application was designed using GET or POST requests.
Forged GET request
The original request would look like something like this, transferring the amount to account #344344:
GET http://acmebank.com/fundtransfer?acct=344344&amount=5000 HTTP/1.1
The attacker’s forged request might look like this. The attacker changes the account number to their own account (#224224 in this example) and increases the transfer amount to $50,000:
http://acmebank.com/fundtransfer?acct=224224&amount=50000
Now the attacker needs to trick the victim into visiting this forged URL while signed into the banking application. The attacker might draft an email like this:
To: Victim
Subject: A gift of flowers for you!
Hello victim,
We know your birthday is coming up and have a special gift for you. Just click here to receive it!
The link “click here” would lead to the forged URL shown above.
Alternatively, the attacker could display a pixel within the email that fires and activates the URL if the victim enables viewing images in their email client. This is more dangerous because it requires no direct user action:
Forged POST request
If the banking application uses POST requests, the user’s original operation would look like this:
POST http://acmebank.com/fundtransfer HTTP/1.1acct=344344&amount=5000
In this case, the attacker would need to craft a