The Wayback Machine - https://web.archive.org/web/20241119035112/https://www.geeksforgeeks.org/what-is-cross-site-request-forgery-csrf/
Open In App

What is Cross Site Request Forgery (CSRF)

Last Updated : 08 Mar, 2019
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Cross Site Request Forgery (CSRF) is one of the most severe vulnerabilities which can be exploited in various ways- from changing user’s info without his knowledge to gaining full access to user’s account.

Almost every website uses cookies today to maintain a user’s session. Since HTTP is a “stateless” protocol, there is no built in way to keep a user authenticated for a series of requests. Asking user for his credentials at each operation is a very bad idea in terms of user experience, This is why cookies are used. Cookies are very efficient for this purpose and are secure if they possess enough entropy, cryptographic strength and are transmitted over a secure channel (using HTTPS).

However, there is a problem, browsers submit cookies to a website whenever a request is made to that website without checking the “origin” of the request. This is where CSRF comes into picture.

The attacker places some code on his website that makes a genuine looking request to the target website. The cookies of the target website will be added by the browser in the request . This will make that forged request a legal one and it’s action will be successfully carried out.

Attack Surfaces:
The attack surfaces for CSRF are mostly HTTP requests that cause a change in something related to the victim, for example: name, email address, website and even password. It is sometimes used to alter the state of authentication as well. (Login CSRF, Logout CSRF) which are less severe but can still be problematic in some cases.

Exploitation:
Consider a website example.com and the attacker’s website evil.com. Also assume that the victim is logged in and his session is being maintained by cookies. The attacker will:

  1. Find out what action he needs to perform on behalf of the victim and find out its endpoint (for example, to change password on target.com a POST request is made to the website that contains new password as the parameter.)
  2. Place HTML code on his website evil.com that will imitate a legal request to target.com (for example, a form with method as post and a hidden input field that contains the new password).
  3. Make sure that the form is submitted by either using “autosubmit” or luring the victim to click on a submit button.

When the victim visits evil.com and that form is submitted, the victim’s browser makes a request to target.com for a password change. Also the browser appends the cookies with the request. The server treats it as a genuine request and resets the victim’s password to the attacker’s supplied value. This way the victim’s account gets taken over by the attacker.

Prevention:

  • On user side:
    User side prevention is very inefficient in terms of browsing experience, prevention can be done by browsing only a single tab at a time and not using the “remember-me” functionality.
  • On Server Side:
    There are many proposed ways to implement CSRF protection on server side, among which the use of CSRF tokens is most popular. A CSRF token is a string that is tied to a user’s session but is not submitted automatically. A website proceeds only when it receives a valid CSRF token along with the cookies, since there is no way for an attacker to know a user specific token, the attacker can not perform actions on user’s behalf.



Previous Article
Next Article

Similar Reads

Cross-Site Request Forgery (CSRF) Protection Methods and Bypasses
Cross-Site Request Forgery is a vulnerability found in web applications that lets a third party attacker perform sensitive actions on a user's behalf. The exploitation of this bug can target normal users as well as site administrators, sometimes leading to a full compromise of a website. Modern websites tend to deploy some protection mechanisms fro
4 min read
Difference Between Stored Cross Site Scripting and Reflected Cross Site Scripting
In today’s online world, keeping web applications secure is crucial to protect both businesses and their users. One common threat is Cross-Site Scripting (XSS), where attackers insert harmful code into websites or web applications. This can cause to serious issues like stealing passwords, redirecting users to dangerous sites, and changing web conte
3 min read
Server Side Request Forgery (SSRF) in Depth
Server-Side Request Forgery (SSRF) :SSRF stands for the Server Side Request Forgery. SSRF is a server site attack that leads to sensitive information disclosure from the back-end server of the application. In server site request forgery attackers send malicious packets to any Internet-facing web server and this webserver sends packets to the back e
4 min read
Fraud vs Forgery
Fraud and Forgery are a part of common use in a sphere of criminality sometimes mistaken for one another, thus, increasing knowledge gaps about their exact meanings. In a way, it is similar in that both of them imply disinformation or falsehood. Some other circumstances make a difference in terms of how the law deals with them. In this article, we
7 min read
Which Ports on Firewall Should be Allowed for IPSEC Site to Site VPN?
Answer: For IPSEC Site-to-Site VPN, allow ports UDP 500 IKE, UDP 4500 NAT-Traversal, and protocols ESP IP Protocol 50 and AH IP Protocol 51 on the firewall.For IPSEC Site-to-Site VPN to function correctly through a firewall, certain ports and protocols must be permitted to ensure secure and reliable communication between the VPN endpoints. Here’s a
1 min read
Difference between Site to Site VPN and Remote Access VPN
Both Site-to-site VPN and Remote access VPN are the types of VPN that stand for Virtual Private Network. In terms of protecting communications over the internet, virtual private networks play an important role. They create encrypted tunnels to ensure that data moved between a user and a network remains confidential and intact. The various types of
5 min read
What is SameSite Cookies and CSRF Protection?
CSRF stands for Cross-Site Request forgery. It allows an attacker to craft a manipulated request via an email or by other means and thereby making state-changing actions in websites that you are currently authenticated as yourself. The intention of CSRF is not to read sensitive data, but to write or make changes to your data for the attackers' bene
5 min read
How to Reduce Risk of Exposure to CSRF, XSRF, or XSS Attacks?
Cross-Site Request Forgery (CSRF) is a Web application security vulnerability where an attacker tricks end-users into performing unwanted actions in which the user is logged in. CSRF has others name like XSRF, sea surf, session riding, cross-site reference forgery, and hostile linking. With the help of social engineering, an attacker can trick the
4 min read
Difference Between XSS and CSRF
Cross-Site Scripting (XSS) and Cross-Site Request Forgery (CSRF) are two common web security vulnerabilities that can have serious consequences for both users and websites. These issues can lead to unauthorized access, data theft, and other significant problems, compromising the security and trustworthiness of the site. What is XSS?Cross-Site Scrip
4 min read
Top 5 Common Mistakes in Technical On-site Interviews
Do you know that less than 10% of candidates passed their on-site interviews as reported in Silicon Valley? Don't forget that those who failed have already passed the phone screen. As the last stage to filter candidates, on-site interview is the most difficult barrier for job seekers. For software engineers, on-site interviews usually involve quite
7 min read
Same Site Scripting
Same Site Scripting is type of vulnerability that is caused by common DNS misconfiguration. But before we dive deep into concepts, let's make sure we have basic understanding of how Internet works. Working of the web : When you try to visit website, your browser communicates with web server where that website's hosted by using IP (internet protocol
3 min read
Machine Learning and Analysis of Site Position Data
The content has been removed as per the author's request.
1 min read
Best Jamstack or Static Site Hosting Providers
There is a popular phrase which many of us hear frequently, "Old is Gold". The Internet has evolved so much from waiting minutes to connect to the Internet using a DialUp modem to downloading megabytes of information at the same time. In a similar way, handing and managing content on the website also changed. We have moved from HTML and CSS in the
5 min read
What is IPv6 Intra Site Automatic Tunnel Addressing Protocol (ISATAP)?
ISATAP is a routable tunneling protocol developed by the IETF as an extension to IPv6, used in scenarios where no other encapsulation is available. It uses IPv4 to transmit data packets over the network. IPv6 Intra Site Automatic Tunnel Addressing Protocol (ISATAP): It is a tunneling protocol that was developed as an extension to IPv6 by the IETF a
2 min read
Introduction to RSS(Rich Summary Site)
Recently, there has been an unprecedented caution regarding data privacy. With infamous leaks and instances of phishing and spamming all around, no one wants to put their personal information out there without restraint, in fear of being the next unfortunate target. This makes staying posted with favored content on the massive expanse of the World
4 min read
5 Best WordPress Security Plugins to Protect Your Site in 2024
In today's digital landscape, where data breaches and cyberattacks are increasingly common, website security is paramount, especially for WordPress users. As the platform powers nearly 40% of all websites, WordPress is a prime target for malicious actors. But fear not, website owners! By implementing the right security measures, you can significant
12 min read
How To Fix the 504 Gateway Timeout Error on Your Site
One of the most unpleasant things that may happen to you when trying to visit a website or service is receiving a 504 Gateway Timeout error. This is the result of an upstream server responding slowly to a gateway or proxy server. It's similar to phoning someone who is engaged or doesn't answer the phone. This thorough article includes a detailed an
10 min read
What is a Social Networking Site (SNS)?
A Social Networking Site (SNS) is an online platform where people can create profiles and connect with friends, colleagues, or others with similar interests. These sites allow users to share ideas, activities, events, and interests within their networks. Some of the famous social networking sites are - Facebook, Instagram, Twitter, and LinkedIn. Us
4 min read
Top 7 Static Site Generators in 2024
In the current high-speed internet era, static site generators are rapidly becoming popular. These powerful utilities provide an attractive way of building performant, secure, and scalable websites as compared to traditional content management systems (CMS). This article is about SSGs(Static Site Generators) and it considers the 7 best competitors
10 min read
10 Best Static Site Generators Hosting Providers in 2024
Due to the communication and the working nature of today’s world, websites have become a vital and distinct part of communication with customers all around the world. This use of websites has brought up the need for smoothness, speed, security, scale, and so on at the interface of the website for better customer experience. This can be fulfilled by
11 min read
7 Best WordPress Table Plugins for Your Site
Tables are an essential part of many websites, providing a clear and concise way to display data. Whether you're running a blog, an e-commerce site, or a corporate website, having a reliable table plugin can enhance your content's readability and functionality. In 2024, several WordPress table plugins stand out for their features, ease of use, and
9 min read
10 Best Usability Testing Tools To Enhance A Site’s UX
Due to the vast range of digital tools and products, it is essential to test the functionalities of the product and the tools. Hence, usability testing is being used to test the functionality of the apps, web, and other products to ensure whether they are efficient enough to be used by the customers. The usability tests can also help companies to i
8 min read
Working of Web Request
To connect to a Web Page on Internet, following steps and protocols play a vital role : Computer connecting to a network cannot perform anything without an IP address. So, Dynamic Host Configuration Protocol (DHCP) runs on client computer to obtain IP address, address of first-hop router, and address of DNS server. Step-1: DHCP Server Discovery. He
4 min read
Construct a simple HTTP request on TCP protocol
HTTP Request : HTTP messages are how data is exchanged between a server and a client. In this, there are two types of messages where one is HTTP client request and the second is the response from the server.Messages in textual form and it is encoded in ASCII form, and span over multiple lines. And messages were openly sent across the connection in
3 min read
How to Respond to an Interview Request (With Examples)
When looking for a position in the ever-expanding job market, it is best to apply to multiple locations at a time. Then, people have to wait, after which the hiring managers and recruiters will reach out to candidates. However, getting the request for the interview does not imply that you only focus on the interview itself to impress recruiters. Yo
10 min read
How to Identify a HTTP Request is Sent by a Local Network Computer or by an Internet Client?
Answer: If it falls within private IP ranges e.g., 10.x.x.x, 172.16.x.x to 172.31.x.x, 192.168.x.x, it's from a local network, otherwise, it's from an internet client.Capture the Client's IP Address When your server receives an HTTP request, it typically includes the client's IP address in the request headers or the server's access logs. Analyze th
1 min read
How To Fix HTTP 408 Request Timeout Error: Solve 408 Error in Steps
When one is browsing, the HTTP 408 error message that is feared by many can be very frustrating. It indicates a "Request Timeout,” which means that there has been a breakdown in communication between your browser and the server you are trying to reach. In this event, while trying to open a page on your web browser, the server fails to receive your
11 min read
RFC (Request For Comment)
Internet as we see it today, is the result of the planning and growth that can be tracked back to a sequence of highly-polished documents called Internet Protocol, Request for Comments (RFCs). RFCs are running as the foundation stones of internet standardization which provide essence, specification, protocol, procedure, and methodology on how disti
8 min read
What is ARQ (Automatic Repeat Request)?
ARQ stands for Automatic Repeat Request also known as Automatic Repeat Query. ARQ is an error-control strategy used in a two-way communication system. It is a group of error-control protocols to achieve reliable data transmission over an unreliable source or service. These protocols reside in the Transport Layer and Data Link Layer of the OSI(Open
7 min read
Postman - Working, HTTP Request & Responses
API...Application Programming Interface... If you're a developer then this word is nothing new for you... Being a developer, you know the importance of API in any kind of application. In simple terms, API is a defined set of rules with some defined methods of communication. With the help of API, software components can interact with each other. You
5 min read
three90RightbarBannerImg