---
title: "What is CSRF and how do I protect against it?"  
description: "What is CSRF and how do I protect against it?"  
author: "Jithin Menon"  
published: 2026-11-19  
updated: 2026-11-19  
canonical: https://www.mindstick.com/forum/163079/what-is-csrf-and-how-do-i-protect-against-it  
category: "Cloud and Security"  
tags: ["CSRF", "web security", "anti-forgery token", "SameSite cookies", "OWASP"]  
reading_time: 1 minute  

---

# What is CSRF and how do I protect against it?

What is a CSRF attack, and does my ASP.NET Core app need protection?

## Replies

### Reply by Shakil Siddique

Cross-Site Request Forgery (CSRF) works because browsers automatically attach cookies to requests. If a user is logged in to your bank site and visits a malicious page, that page can make the browser send a request such as "transfer money" to your site, and the cookie goes along with it.

Protections:

- **Anti-forgery tokens**: the server puts a secret token in each form and rejects a POST without a valid one. ASP.NET Core Razor Pages do this automatically, and MVC offers `[ValidateAntiForgeryToken]` or `AutoValidateAntiforgeryToken`.
- **SameSite cookies** (Lax or Strict) stop cookies being sent on most cross-site requests. They are a good extra layer.
- **Never change data with GET requests.** Use POST, PUT or DELETE.
- For APIs that use bearer tokens in the Authorization header (not cookies), CSRF is much less of a risk, because the browser does not attach those automatically.

So yes, a cookie-based app that changes data needs protection. Check that every state-changing endpoint is covered.


---

Original Source: https://www.mindstick.com/forum/163079/what-is-csrf-and-how-do-i-protect-against-it

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
