One thing about cybersecurity that doesn’t get nearly enough attention: we spend most of our time talking about stolen passwords, exploited vulnerabilities, and broken authentication. It’s easy to forget that an attacker doesn’t always have to break into an account at all.

CSRF attack scene showing an unintended browser request targeting account actions like changing email, updating password, or transferring funds

Sometimes all they need is for your browser to do something it was never meant to do.

That’s where Cross-Site Request Forgery (CSRF) comes in.

Quick Summary

A CSRF attack tricks a logged-in user’s browser into sending an unauthorized, state-changing request to a web application that trusts active session cookies—without stealing the user’s password or session token.

When you first run into CSRF, it sounds almost too simple. Get the victim to open a malicious page, let their browser fire off a request to a legitimate site, and have that request carry out an action on their behalf. Easy enough, right?

The deeper you dig, though, the more interesting it gets. CSRF isn’t really about defeating authentication. It’s about abusing trust that’s been placed in the wrong place.

And misplaced trust is a bigger problem than we tend to give it credit for.

Your Browser Isn’t Always on Your Side

Let’s start with something most of us never think twice about.

You log into a site, it hands your browser a session cookie, and from then on the browser quietly attaches that cookie to every request you make to that site. That’s the reason you stay logged in instead of retyping your credentials on every page.

Convenient? Definitely. It also creates a pretty interesting security problem.

Your browser doesn’t really know why a request is happening. It knows where the request is headed and, depending on the situation, attaches the credentials that belong to that destination.

Say you’re logged into your bank in one tab. In another tab you open some unrelated site, and that page contains something that makes your browser send a request to your bank. The browser may still tag that request with your banking session cookie. The bank receives it, sees a valid session, and may well assume you were the one who kicked off the action.

Except you weren’t.

You never started that transaction. You never clicked a transfer button. You didn’t touch the bank’s site at all.

Your browser just carried your authentication along on a request someone else engineered.

That’s the basic idea behind CSRF.

So, What Actually Is CSRF?

How CSRF works diagram showing a logged-in user lured to a malicious page while the browser sends session cookies to a vulnerable site

Cross-Site Request Forgery is a flaw that lets an attacker get an already-logged-in victim’s browser to carry out an action the victim never intended, on a site where they have a live session.

The key point is that the attacker usually doesn’t know the victim’s password, session cookie, or any other credential.

The victim already has a working session, and the attacker rides on top of it.

For this to work, a handful of conditions usually have to fall into place:

  • The victim has to be logged into the vulnerable application.
  • The app relies on credentials the browser attaches automatically, like session cookies.
  • It accepts a state-changing request without properly checking that it came from a legitimate, trusted context.
  • And the victim has to be tricked into triggering the request, commonly by landing on a malicious or compromised page.

It’s the combination of these things that makes CSRF possible.

Nothing has to be stolen here. The attacker only needs the victim’s browser to act.

A Simple Example

Comparison of a legitimate HTTP POST request with a CSRF token versus a forged CSRF request without a token

Picture a made-up app that lets users change the email address on their account. A normal request would look something like this:

POST /account/change-email

The app gets the new address along with the user’s authenticated session and updates the account.

Now suppose the app checks only that someone is logged in. It doesn’t care whether the request came from a real interaction with its own UI, and it asks for no unpredictable, per-request token.

An attacker can put up a page that makes a browser submit that request without the user wanting it.

If the victim is logged in, the browser will attach the session cookie on its own. The app sees an authenticated request and goes ahead and processes it.

The victim’s email can be swapped out even though they never opened the account settings page.

The attacker never authenticated as the victim. The victim’s browser did it for them.

That’s the detail that makes CSRF so interesting.

The browser is doing exactly what it was built to do, and the app is doing exactly what its checks tell it to do. Put them together and you still get an action the user never asked for.

Why Authentication Alone Isn’t Enough

This is the part I’d pay attention to if you’re learning web security or working through bug bounty targets. If you are building your foundational security knowledge, check out our beginner’s guide to cybersecurity to see how core web defenses fit together.

We tend to treat authentication as a hard security boundary. A valid session cookie, bearer token, or similar credential tells the server who’s making the request.

But authentication only answers one fairly narrow question:

Who is this request associated with?

It doesn’t necessarily answer a second one:

Did this user actually intend to perform this action?

Those are two different questions.

A valid session cookie proves the request belongs to an authenticated session. It says nothing about whether the user clicked a button, looked over the action, or consciously decided to go ahead with it.

CSRF lives in that gap between who sent the request and what they meant to do.

That’s why an app can have perfectly working login and session handling and still be wide open to CSRF.

The Myth That CSRF Only Applies to Money Transfers

Common CSRF targets including change email, update password, modify account settings, add or change address, link another account, and perform admin actions

Bring up CSRF and most people immediately think of money moving from one account to another.

It’s a decent example, but it makes the bug look a lot narrower than it really is.

Depending on what the app does and how it’s protected, CSRF can go after just about any sensitive action that changes state.

A few examples:

  • Changing the email address or phone number on an account.
  • Updating a password or the account recovery options.
  • Tweaking privacy or security settings.
  • Adding a new address or changing delivery details.
  • Linking a third-party account or integration.
  • Creating, deleting, or editing resources.
  • Carrying out admin actions in privileged apps.

How bad it gets depends entirely on what that endpoint lets the attacker make the browser do.

A CSRF bug that flips a harmless preference might barely matter. One that changes account recovery details, switches off a security control, or performs a privileged action is a different story.

The bug is just the mechanism; the severity comes from the action being forged.

But What About SameSite Cookies?

CSRF is harder to pull off in modern browsers than it once was, and a big part of that is the SameSite cookie attribute and how widely it’s now used.

SameSite decides whether a cookie gets attached to requests coming from what the browser considers a cross-site context. Depending on the value you set, it can stop cookies from going out with certain cross-site requests, which cuts down the chances of an attacker abusing someone’s logged-in session.

The values you’ll usually run into:

  • Strict: cookies are generally blocked from cross-site contexts altogether.
  • Lax: cookies are held back from most cross-site requests, though some top-level cross-site navigations that use safe methods can still carry them.
  • None: permits cross-site use of the cookie, as long as the browser’s conditions are met, including Secure.

That’s a meaningful mitigation, no doubt. But it isn’t a reason to assume an app is automatically safe from CSRF. How cookies behave depends on context, the browser implementation, the type of request, and how things are configured. More to the point, SameSite is only one layer.

Apps should still put proper CSRF defenses in place for sensitive state-changing actions instead of leaning entirely on browser cookie rules.

Controls do their job best when they back each other up, not when a single setting is expected to solve everything.

The Interesting Cases: CSRF Doesn’t Always Look the Way You’d Expect

This is where it starts to get interesting when you’re the one doing the testing.

CSRF variations diagram comparing Login CSRF into an attacker account and Client-Side CSRF manipulating JavaScript inputs

The classic version has an attacker making the victim’s browser send a request to a vulnerable app. But there are variations that don’t fit that neat picture.

1. Login CSRF

Most CSRF talk revolves around actions that happen after the victim is already logged in.

Login CSRF turns that assumption on its head.

In some flawed implementations, an attacker can get a victim logged into the app using an account the attacker controls. The victim then goes about their business on that account without realizing it, maybe typing in personal details, uploading documents, or attaching sensitive data to it.

They think they’re in their own account, but the app has actually signed them into somebody else’s.

That opens up privacy and data-exposure problems, particularly once the victim starts entering information they believe is going into their personal account.

It’s a useful reminder that the login flow itself can carry CSRF weaknesses, not only the features you reach after logging in.

2. Client-Side CSRF

Client-side CSRF is another variant worth knowing about.

Here the attacker doesn’t build the request themselves. They tamper with input that the app’s own JavaScript uses to build its requests.

Think of an app that pulls certain values out of the URL and uses them to decide which API endpoint to hit or which action its JavaScript should run.

If those inputs aren’t validated properly, an attacker can steer them so that the app’s JavaScript performs an authenticated action nobody asked for.

It’s an interesting one because developers may have locked down server-side CSRF for ordinary requests and completely missed the logic running in the browser.

The request comes from trusted application code, but untrusted input has influenced what that code decides to do.

The trust boundary has moved.

And anywhere that boundary moves, there’s something worth taking a closer look at.

How Do We Actually Prevent CSRF?

How to prevent CSRF checklist covering CSRF tokens, SameSite cookies, Origin or Referer checks, proper HTTP methods, and defense in depth

The good news is that we already know how to defend against CSRF. The tricky part is putting those defenses in place correctly, everywhere they’re needed. For detailed implementation patterns, see the OWASP Cross-Site Request Forgery Prevention Cheat Sheet.

CSRF Tokens

The most common defense is probably the synchronizer token pattern.

The app generates a token that can’t be guessed, ties it to the user’s session, and insists it be included with sensitive requests. The server checks the token before it does anything.

Browser security rules usually stop an attacker on some other site from reading that token, so they can’t just build a valid request themselves.

The token needs to be unpredictable, checked properly, and handled carefully. Having a parameter called csrf_token in a request proves nothing on its own. What counts is whether the server actually verifies it and throws out requests where the token is missing, invalid, or doesn’t match.

SameSite Cookies

SameSite settings make browsers less willing to attach cookies to cross-site requests.

It’s a decent extra layer, especially alongside real request validation.

You do need to pick the setting based on what the app actually needs, though. Go too strict and you’ll break legitimate functionality.

Origin and Referer Validation

Apps can check the Origin header too, and fall back on the Referer header as an additional signal where that makes sense.

Both headers give you a clue about where the request originated.

But you can’t bolt them on carelessly. The validation has to be exact, has to deal with missing headers according to your security policy, and has to avoid sloppy checks that fall over because of bad parsing or loose comparisons.

Protect State-Changing Actions

Don’t use GET requests to change state.

Anything that modifies data should use the right HTTP method and go through proper validation. Switching from GET to POST doesn’t stop CSRF by itself, but it does make it easier to keep reading and writing cleanly separated.

Defense in Depth

A well-built app shouldn’t hang everything on one CSRF control.

Put CSRF tokens, sensible SameSite settings, Origin validation, careful auth design, and solid authorization checks together and you’re in a much better position.

Just as important: go over every sensitive endpoint. It’s common to secure the main UI and then forget the secondary endpoints, old legacy routes, APIs, or the actions nobody uses very often.

You don’t secure an app by securing the page. You secure it by protecting the operation.

What I Look for When Testing

When I start testing a web app, I try not to obsess over spotting an interesting-looking parameter or request. Understanding broader threat landscapes like common types of cyber attacks also helps put request-forgery risks into context.

What I want to know is what the app actually trusts.

Does the endpoint change state? Does authentication come from cookies? Is there a CSRF token, and if so, is it really checked? What happens when the token is missing or wrong? Are there Origin checks? Can the same action be reached through another endpoint with weaker controls?

And above all: what happens if this request fires without the user ever intending it?

That last question usually tells you more than whether you can replay the request in a tool.

A request that fires in Burp Suite isn’t automatically a bug, and a request that succeeds without a CSRF token isn’t automatically exploitable either. You have to understand the auth mechanism, how the browser behaves, what controls are in place, and whether the attack conditions are realistic.

The line between an interesting behavior and a real vulnerability is understanding the whole chain.

A Little Perspective

Cybersecurity has a funny way of humbling you.

You can spend years studying, stacking up certifications, learning tools, grinding through labs, and trying to figure out how systems really work. You can be the person with good grades, finished projects, and countless hours put in, honestly believing that enough hard work would make everything click into place.

Then you leave the classroom and find that the industry doesn’t always run the way you pictured it.

I’ve felt that gap myself. Doing well academically doesn’t automatically turn into opportunities, and sometimes it feels like everything you’ve worked for is sitting there waiting on somebody else to give you a shot.

It did change how I go about learning, though.

I don’t just want to be able to expand the acronym. I want to know why the bug exists, what the browser does to make it possible, which assumptions developers lean on, where those assumptions break down, and how a tester can tell a theoretical risk from an actual issue.

That’s the bit I care about.

Anyone can fire a request with a tool, copy a payload, or memorize a list of vulnerability names.

Knowing why that request works is a completely different skill.

Final Thoughts

CSRF isn’t always about sophisticated payloads, complicated chains, or a dramatic exploit.

Sometimes it’s nothing more than a site trusting a request because the browser showed up with the right credentials.

That’s the uncomfortable bit.

Your browser might be carrying your identity, but that doesn’t mean it’s carrying your intent.

Once you see that distinction, CSRF stops being just another name to memorize. It becomes a lesson in how authentication, trust, browser behavior, and app logic overlap, and how things go wrong when those pieces were never designed to work together.

Next time you’re staring at a request in Burp, don’t stop at asking whether it works. Ask who kicked it off, what the app is trusting, and whether the user actually meant for it to happen.

Sometimes the best find is hiding in a request that looks completely legitimate.