We may earn an affiliate commission when you visit our partners.

Cross-site Request Forgery (CSRF)

Save
May 11, 2024 Updated July 12, 2025 12 minute read

Cross-site Request Forgery (CSRF) is a type of attack that tricks a user into submitting a request to a web application that they are authenticated to, without their knowledge or consent. This can be done by sending the user a specially crafted link or by embedding a script into a website that they visit.

How CSRF Works

CSRF attacks work by exploiting the way that web browsers handle cookies. When a user is logged into a website, their browser sends a cookie with every request to that website. This cookie contains a unique identifier that allows the website to identify the user and track their session. If an attacker can trick a user into clicking on a specially crafted link or visiting a website that embeds a script, they can send a request to the web application that is authenticated with the user's cookie. This request can be used to perform any action that the user is authorized to perform, such as changing their password or making a purchase.

Preventing CSRF Attacks

There are a number of ways to prevent CSRF attacks, including:

  • Use CSRF tokens: CSRF tokens are random values that are generated by the web application and sent to the user in a cookie or header. When the user submits a request to the web application, the CSRF token must be included in the request. If the CSRF token is missing or invalid, the request will be rejected.
  • Validate the origin of requests: The web application can check the origin of requests to make sure that they are coming from the expected domain. This can be done by checking the HTTP Referer header.
  • Use HTTP-only cookies: HTTP-only cookies are cookies that cannot be accessed by JavaScript. This prevents attackers from using JavaScript to steal CSRF tokens.
  • Educate users about CSRF attacks: Users should be aware of the risks of CSRF attacks and should avoid clicking on links or visiting websites that they do not trust.

Benefits of Learning About CSRF

Path to Cross-site Request Forgery (CSRF)

Take the first step.
We've curated nine courses to help you on your path to Cross-site Request Forgery (CSRF). Use these to develop your skills, build background knowledge, and put what you learn to practice.
Sorted from most relevant to least relevant:

Share

Help others find this page about Cross-site Request Forgery (CSRF): by sharing it with your friends and followers:

Reading list

We've selected six books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Cross-site Request Forgery (CSRF).
Covers a wide range of web application security topics, including CSRF attacks. It valuable resource for anyone who wants to learn more about web application security and how to protect their applications from attack.
Provides a comprehensive overview of web application security. It includes a chapter on CSRF attacks that provides detailed information on how to prevent CSRF vulnerabilities in web applications.
Covers a wide range of web application security topics, including CSRF attacks. It valuable resource for anyone who wants to learn more about web application security and how to protect their applications from attack.
Provides a practical guide to penetration testing. It includes a chapter on CSRF attacks that provides detailed instructions on how to test for and prevent CSRF vulnerabilities.
Provides a comprehensive overview of security in ASP.NET Core. It includes a chapter on CSRF attacks that provides detailed information on how to prevent CSRF vulnerabilities in ASP.NET Core applications.
Provides a beginner-friendly introduction to web application security. It includes a chapter on CSRF attacks that provides basic information on how to prevent CSRF vulnerabilities.
Table of Contents
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2025 OpenCourser