Course contentsShow
← Security
Lesson 851 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

Why Cookie-Based Authentication is Vulnerable

Understanding how browsers automatically include cookies with cross-origin requests enabling CSRF attacks.

Why Cookie-Based Authentication is Vulnerable

What you'll learn: How the browser's automatic cookie-sending behavior creates the perfect storm for CSRF attacks.

The Automatic Cookie Problem

When you log into a website, the server typically sends you a session cookie that proves you're authenticated. Here's the dangerous part: your browser automatically includes this cookie with every request to that domain — even if the request originates from a completely different website.

This isn't a bug; it's how browsers are designed to work. When you visit evil.com and it tricks your browser into sending a request to bank.com, your browser helpfully attaches your bank.com authentication cookie. The bank's server sees a valid session cookie and thinks, "This is the legitimate user!" — but you never intended to make that request.

Why This Enables CSRF

Imagine your house key automatically appears in your hand whenever someone mentions your address — even if a stranger says it. That's how cookie-based authentication works with cross-origin requests.

The server can't tell the difference between:

  • Legitimate request: You clicking "Transfer $100" on bank.com
  • CSRF attack: evil.com silently submitting the same form using your browser

Both requests arrive with your valid session cookie attached. The bank sees the cookie, validates your session, and processes the transfer.

The Core Vulnerability

The browser doesn't ask, "Did the user intend to send this request?" It simply follows the rule: "If you're making a request to bank.com, attach the bank.com cookies." This automatic behavior is what attackers exploit in CSRF attacks — they leverage your existing authenticated session without needing to steal your credentials.

Key Takeaway: Cookie-based authentication is CSRF-vulnerable because browsers automatically attach cookies to cross-origin requests, allowing attackers to perform authenticated actions without the user's knowledge or consent.