LOGBOOK

HELP

Quiz Entry - updated: 2026.07.31

How does a Cross-Site Request Forgery (CSRF) attack work?

A malicious page makes the victim's logged-in browser fire a state-changing request to a trusted site; the browser auto-attaches the session cookie, so the request looks legitimate.

CSRF: the attacker's hidden form makes the victim's logged-in browser POST with the session cookie auto-attached.

* CSRF — the attacker's hidden form makes the victim's logged-in browser POST to the bank with the session cookie auto-attached, so the forged transfer looks legitimate. *

CSRF attack flow:

  1. The victim logs into their e-bank; the bank sets a session cookie, say JSESSIONID=A23dc…
  2. In the same browser, still logged in, the victim opens the attacker's page and clicks something innocuous — a "CLICKME" button
  3. That page carries a hidden form aimed at the bank:
<form action="https://e-bank.com/doTransfer" method="POST">
  <input name="fromAccount" value="VICTIMS_ACCOUNT">
  <input name="toAccount" value="ATTACKERS_ACCOUNT">
  <input name="amount" value="10000">
</form>
  1. The browser submits it and — because the request goes to e-bank.comautomatically attaches the bank's cookies, session cookie included
  2. The bank receives a well-formed, correctly authenticated transfer request and executes it

Key insight: the browser attaches a site's cookies to any request aimed at that site, no matter which page triggered it. So on the wire a forged request is indistinguishable from a genuine one, and the server has nothing to check.

What the attacker never gets: they cannot read the bank's pages or responses — the same-origin policy blocks that. CSRF is a write attack: it makes something happen (transfer, password change, purchase) while flying blind. That asymmetry is exactly what the defences exploit — every one of them requires the request to carry a value the attacker can trigger but not read.

Go deeper:

From Quiz: SPRG / Input Validation & Output Encoding | Updated: Jul 31, 2026