What is CSRF? (Cross-site request forgery attack)
Very few Internet users are aware of the dangers they may face when surfing the web. In addition to spear phishing, cross-site request forgery is currently a popular tool for cyÂberÂcrimÂiÂnals. Hackers can use this method to initiate money transfers to foreign bank accounts via online banking websites. But how exactly does this attack method work? And how can you protect yourself from it?
What is CSRF?
CSRF: Cross-site request forgery (CSRF or XSRF) is an attack method mostly used for comÂmitÂting Internet fraud. Criminals use HTTP requests to take over a userâs auÂthenÂtiÂcatÂed session (session riding) and perform malicious actions.
Suppose youâve logged in to a website. After logging in, you remain logged in for the duration of the session (this time period can vary widely depending on the site) without having to re-enter your password. CyÂberÂcrimÂiÂnals take advantage of this situation. They know that logged-in users can usually perform more privÂiÂleged actions than users who are not logged in.
In a nutshell, hereâs how CSRF works: While youâre logged into the site, you visit another website created by the hacker. Once there, you perform some action, such as clicking a button. The attacker then sends an HTTP request to the site youâre signed in to and uses your identity to execute a malicious action because your session is still active. All the attacker needs to know is the correct HTTP request, which is relÂaÂtiveÂly easy to figure out.
The server of the website recÂogÂnizes the HTTP request as correctly strucÂtured and sees from your cookies that you (or your browser) are still logged in. The server executes the action and you might not realize that an action has been taken on your behalf.
The CSRF attack is sucÂcessÂful because the receiving server doesnât check where the request is coming from. It doesnât know whether the HTTP request was generated by the website itself or by an outside source. The attacker takes advantage of a weakness in the browser, which forwards the requests without assessing the conÂseÂquences.
Three types of CSRF attacks are carried out most freÂquentÂly. The most popular technique is to plant an exploit URL. This URL is hidden on an external website or in an email. Opening the URL triggers the HTTP request. In principle, you can detect this type of URL if youâre paying close attention. However, social enÂgiÂneerÂing and URL spoofing can be used to disguise the origin of the URL.
There is also potential for cross-site scripting (XSS): Some hackers, instead of setting up their own malicious website, maÂnipÂuÂlate an existing website through XSS, which is then used to perform criminal actions without the website operatorâs knowledge. In this type of attack, JavaScript is typically planted on a website to carry out a CSRF attack.
A cross-site request forgery attack is also possible if attackers manage to place malware on the victim's computer. This allows attackers to directly instruct the browser to send the HTTP request. However, attackers have even more options if they're able to plant viruses or malware on the client.
Example of a cross-site request forgery attack
Weâll use online banking for our example of CSRF because it best ilÂlusÂtrates the potential conÂseÂquences of the attack method. Suppose you log in to your online banking account. You go to the special form for transÂferÂring funds. When you complete the form and click the conÂfirÂmaÂtion button, a specific HTTP request is sent to the server and the funds transfer is made. However, the attacker knows exactly how the form and HTTP request are strucÂtured and can replicate both. Next, the fraudsterâs account details and an amount set by the fraudster are inserted into the form.
The hacker can then set up a website (or send an email) that will attract your interest. The website or email asks you to click on a seemingly harmless link that activates the fake HTTP request. The request is then sent to the bank, which performs the action requested by the hacker. Thereâs no reason for the server not to execute the action because the session is still active and the request is correct. So the money is simply transÂferred. You wonât notice anything until the next time you check your account balance.
Weâve used the example of a bank account because it shows how bad the conÂseÂquences of CSRF can be. But in reality, bank websites and funds transfer mechÂaÂnisms in parÂticÂuÂlar have multiple layers of proÂtecÂtion against such attacks.
Other attack scenarios:
- Social media: Attackers post comments or likes on behalf of logged-in users.
- Website adÂminÂisÂtraÂtion: If a victim has access to the backend, attackers can create new users or delete the entire website without the adÂminÂisÂtraÂtorâs knowledge.
- Online shopping: An attacker can make purchases from an online store without the userâs knowledge.
CSRF attacks always aim to perform specific actions on your behalf. However, CSRF canât be used to extract inÂforÂmaÂtion because attackers canât see into your account. Suppose youâre on a website with a download function for sensitive data (such as account stateÂments). An attacker could trigger the download, but still wouldnât be able to access the data because it would be on your device.
Security measures: How can you prevent CSRF attacks?
Use caution and care online
As a user, you need to exercise caution. Youâre not likely to fall victim to an attack like this if you donât visit quesÂtionÂable websites or open susÂpiÂcious emails. To protect yourself from CSRF, you should end active sessions on security-critical websites before you visit sites that may not be trustÂworÂthy.
Check your devices for malware
Ensure that your device (PC, laptop, smartÂphone, etc.) is free of malware. Itâs much harder to prevent CSRF if a backÂground apÂpliÂcaÂtion is spying on you. Once your device is infected, youâre vulÂnerÂaÂble to many other types of attacks.
CSRF proÂtecÂtion by website operators
Website operators can also protect visitors to their sites: Attackers can carry out cross-site forgery attacks because they know the exact structure of vulÂnerÂaÂble forms and HTTP requests. But if a random factor is inÂtroÂduced, the hacker will usually give up. The website can create a one-time token (a random string) and make it part of the HTTP request. If the server receives a request that contains no token or an invalid token, the request is auÂtoÂmatÂiÂcalÂly rejected.
Two-factor auÂthenÂtiÂcaÂtion
Online banking sites usually use two-factor auÂthenÂtiÂcaÂtion. Before making a funds transfer, the user has to enter a TAN code that is not provided via the website. This method protects against CSRF as well as other types of attacks. Even if attackers steal the userâs creÂdenÂtials, they wouldnât be able to transfer the funds without the second factor.
Referrer header
In theory, the referrer header should offer adequate proÂtecÂtion. This part of the HTTP request idenÂtiÂfies where the request is coming from. It allows websites to filter out all foreign requests. However, referrer headers have not always proven reliable. Browser exÂtenÂsions such as adÂblockÂers change or delete the referrer header. Users with these exÂtenÂsions would then no longer be able to use the website.
Log out when youâre done
One preÂcauÂtion that will deter but not necÂesÂsarÂiÂly prevent all attacks is to define session timeouts. As a website operator, you have to strike a balance between risk and user-friendÂliÂness. Online banking sites time out after a few minutes of inÂacÂtivÂiÂty. But other websites, such as many social media sites that handle less sensitive data, keep sessions active for days. A CSRF attack canât happen once the user is logged out of the site.
