CSRF Notes
CSRF Notes
What is CSRF?
A online security flaw known as Cross-Site Request Forgery (CSRF) enables a
hacker to deceive a user into carrying out undesirable actions on a website
where they have verified their identity. CSRF forges requests without the user's
permission in order to take advantage of the confidence that a web application
places in their browser. In order to carry out illegal operations on the online
application, such as altering account information, transferring money, or
carrying out other tasks that the authenticated user is allowed to carry out, the
attacker coerces the victim into sending a maliciously designed request.
How does a CSRF Attack work?
EXAMPLE SCENARIO:
Imagine a situation when a person is both visiting other websites and logged
into their bank.com online banking account. The following form is present on
the malicious webpage that the attacker is hosting:
<form action="https://bank.com/transfer" method="POST">
<input type="hidden" name="amount" value="5000">
<input type="hidden" name="account" value="attacker123">
</form>
The form is configured to submit a request for a money transfer to the bank.
While remaining logged in to the banking website, the victim unintentionally
accesses the malicious website. The malicious page loads quickly and uses the
victim's session to submit the form to the bank, prompting the bank to transfer
$5,000 from the user's account to the attacker's account.
Since the request originates from an authenticated session, the banking website
treats it as though the user has voluntarily made it, thus there's no need to be
suspicious.
A REAL WORLD EXAMPLE:
A CSRF attack happened in the real world in Gmail (2007). A CSRF exploit
was created by attackers to alter Gmail accounts' forwarding configurations. An
image tag was embedded in a rogue website to carry out the attack:
‘ <img
src="https://mail.google.com/mail/?view=up&act=cf&forward=attacker@gmail
.com"> ’
The request was issued using the authenticating cookies of the logged-in Gmail
user, and Gmail inadvertently altered the user's forwarding address to the
attacker's email.
Impact of CSRF
Financial Loss: Unauthorized fund transfers resulting from CSRF can
seriously harm one's finances.
Account Compromise: Account takeover can occur when hackers alter
email addresses, passwords, or account settings.
Data Integrity Breach: Malicious alterations to user data, such as
preferences or profile information.
Service Disruption: Administrator rights can be abused by attackers to
stop or interfere with services.
Mitigation Measures
1. Anti-CSRF Tokens: Introduce distinct anti-CSRF tokens for every form
submission or session. Requests should not be processed until the server
has validated the token.
Example- Including a hidden input field in forms:
<input type="hidden" name="csrf_token" value="generated_token">
4. Referer and Origin Header Validation: Verify that requests are originating
from a reliable domain by looking at the "Referer" or "Origin header."
REFERENCES
1. https://owasp.org/www-community/attacks/csrf
2. https://portswigger.net/web-security/csrf
3. https://brightsec.com/blog/cross-site-request-forgery-csrf/
4. https://owasp.org/www-project-web-security-testing-
guide/latest/4-Web_Application_Security_Testing/06-
Session_Management_Testing/05-
Testing_for_Cross_Site_Request_Forgery
5. https://cheatsheetseries.owasp.org/cheatsheets/Cross-
Site_Request_Forgery_Prevention_Cheat_Sheet.html
6. https://brightsec.com/blog/csrf-mitigation/