Home
Cybersecurity & AI Security / Part 20 — CSRF, SSRF, and Request Forgery

CSRF, SSRF, and Request Forgery

CAP, ACID vs BASE, latency numbers, back-of-envelope estimation, single points of failure — the vocabulary every system designer thinks in.


Core Philosophy: Some attacks don’t break into a system — they trick something trusted into acting on the attacker’s behalf. Request forgery is exactly this: making a request that appears legitimate because it comes from a trusted source. Two cousins share the idea — CSRF tricks a victim’s browser into sending a request, SSRF tricks a server into sending one. They sound alike, are constantly confused, and are genuinely different. This page makes the difference clear.

Part 1: The Problem

A request is trusted based on where it comes from. A request from a logged-in user’s browser carries their session and is treated as their legitimate action. A request from inside a company’s own server is treated as trusted internal traffic.

Request forgery attacks abuse those trust assumptions. Instead of stealing credentials or exploiting a parsing bug, the attacker arranges for a trusted entity — the victim’s browser, or the application’s own server — to make a request the attacker wants. The request looks legitimate because, mechanically, it is coming from the trusted source. This section covers the two main forms.

Part 2: CSRF — Cross-Site Request Forgery

The trick: make a victim’s browser send a request to a site where the victim is logged in, performing an action the victim never intended.

The setup that makes CSRF possible: recall from 0.3 that a browser automatically attaches the relevant cookies — including the session cookie — to every request to a site. The browser does this no matter what caused the request. So if an attacker can cause the victim’s browser to fire a request at a target site, that request rides along with the victim’s session and looks completely authentic.

text
   1. Victim is logged in to bank.com (has an active session).
   2. Victim visits the attacker's page (or opens a crafted
      email/link) while still logged in.
   3. The attacker's page silently makes the victim's browser
      send a request to bank.com — e.g. a funds transfer.
   4. The browser AUTOMATICALLY attaches the victim's bank.com
      session cookie.
   5. bank.com sees a properly-authenticated request and
      performs the action — a transfer the victim never made.

The victim has authentication; CSRF abuses it. The attacker never sees the victim’s password or session — they don’t need to. They just need the victim’s browser to fire the request while the victim is logged in.

Impact: any state-changing action the victim is allowed to do — change their email or password, transfer funds, make a purchase, change settings — can be triggered without consent.

The defenses (built in Phase 4.2):

Part 3: SSRF — Server-Side Request Forgery

The trick: make the application’s own server send a request to somewhere the attacker chooses.

Many applications fetch URLs as part of their normal work — loading an image from a URL you give, fetching a webhook, importing data from a link, generating a preview of a link. If the app takes a user-supplied URL and the server goes and requests it, an attacker can supply a URL pointing somewhere they should never be able to reach.

Why that’s powerful: the server often sits inside a trusted network, behind the firewall. The attacker, out on the internet, cannot reach those internal systems — but the server can. SSRF turns the server into a proxy, letting the attacker reach internal-only targets through it.

text
   The attacker cannot reach internal systems directly:

   Attacker ──✗──► [firewall] ──► internal services

   But with SSRF, the attacker tells the SERVER what to fetch:

   Attacker ──► "fetch this URL" ──► Web Server
                                         │  (the server is
                                         │   trusted & inside)
                                         ▼
                                  internal-only services,
                                  cloud metadata endpoints,
                                  other internal hosts

What SSRF can reach:

SSRF is rated severe and has climbed the OWASP Top 10 precisely because modern cloud architectures make its impact so high.

The defenses (built in Phase 4.2):

Part 4: CSRF vs SSRF — Settling the Confusion

The names are similar; the attacks are not. Lock in the difference:

CSRF SSRF
Who is tricked into making the requestThe victim’s browser (client-side)The application’s server (server-side)
Whose trust is abusedThe site’s trust in the victim’s browser/sessionThe network’s trust in the server
Attacker’s goalPerform an action as the victimReach systems the attacker can’t reach directly
Classic impactUnwanted state change (transfer, settings)Access to internal services, cloud credentials
Primary defenseCSRF tokens, SameSite cookiesURL allowlisting, blocking internal ranges

One memory hook: CSRF → the Client (browser) is tricked. SSRF → the Server is tricked. Same idea — forge a request from a trusted source — different trusted source.

Part 5: The Wider Family — Forgery and Trust

CSRF and SSRF are the two you must know cold, but the pattern — abusing trust in the origin of a request — shows up more widely. Briefly, so you recognize the family:

The unifying lesson — and the bridge to defense: trust must be based on verification, not on appearance. “This request came from the user’s browser” or “this request came from our server” is an appearance of legitimacy. CSRF tokens, URL allowlists, and validating untrusted headers all replace assumed trust with verified trust. That principle — verify, don’t assume — runs through the entire defensive half of the curriculum.

Part 6: Finding Request Forgery

How you test for each:

Finding CSRF:

text
1. Find STATE-CHANGING actions (change email, transfer,
      update settings) — CSRF only matters for actions that
      DO something.
2. Inspect the request. Does it include an unpredictable
      anti-CSRF token? Is SameSite set on the cookie?
3. If there's no token (or the token isn't validated, or
      it's predictable/reusable), the action may be forgeable.
4. Confirm by crafting a test request from a different
      origin — see if it succeeds.

Finding SSRF:

text
1. Find features where the SERVER fetches a URL — image-from-
      URL, link previews, webhooks, imports, PDF generators.
2. Supply a URL you control and confirm the SERVER (not your
      browser) makes the request.
3. Test whether you can point it at internal addresses or
      the cloud metadata endpoint.
4. Assess impact carefully and responsibly.
⚖️ Ethics. For CSRF, test against your own lab accounts — don’t perform real unwanted actions on real users. For SSRF, demonstrating that the server fetches an attacker-chosen URL is usually enough to prove the bug; do not use it to actually pull cloud credentials or rummage through a real internal network — that’s a severe crime even on an in-scope program. As always: prove it, don’t exploit it. Page 1.0 governs.

📓 Key Terms

Term Plain meaning
Request forgeryMaking a trusted entity send a request the attacker wants.
CSRFCross-Site Request Forgery — tricking a victim’s browser into sending an authenticated request.
CSRF tokenA secret, unpredictable per-session value that validates legitimate requests — the main CSRF defense.
SameSite cookieA cookie setting limiting whether it’s sent on cross-site requests.
SSRFServer-Side Request Forgery — tricking the server into making a request.
Cloud metadata endpointAn internal cloud address holding config/credentials — a prime SSRF target.
AllowlistA list of explicitly permitted values (e.g. URLs) — everything else denied.
Open redirectAn app redirecting to an unvalidated user-supplied URL.

🧪 Hands-On Lab

Only on your own lab or deliberately vulnerable practice apps.

Task 1 — Perform a CSRF attack. On a deliberately vulnerable app, find a state-changing action with no CSRF protection. Craft a simple page or request that triggers that action using your own logged-in lab session. Watch the action happen “as you” without you using the real form.

Task 2 — See a CSRF token defend. Find an app (or app feature) that does use CSRF tokens. Capture a legitimate request in Burp and note the token. Try to replay the request without it, or with a wrong token. See it rejected. That’s the Part 2 defense working.

Task 3 — Inspect SameSite. In your browser dev tools, examine cookies on various sites and look at the SameSite attribute. Connect what you see to how it limits CSRF.

Task 4 — Perform an SSRF attack. On a deliberately vulnerable app, find a feature where the server fetches a URL. Supply a URL you control (or an internal-style address the lab exposes) and confirm the server made the request, not your browser.

Task 5 — Reach the “internal” via SSRF. In a lab designed for it, use SSRF to reach a service that’s only reachable from the server side. Experience how SSRF turns the server into a proxy into places you can’t otherwise reach.

Task 6 — Explain the difference. Write, in your own words, the difference between CSRF and SSRF — who is tricked, whose trust is abused, what the attacker gains. If you can explain it clearly, you’ve beaten the most common confusion in this topic.

⚠️ Common Mistakes

✅ Recap & What’s Next

Next (2.9): Many breaches need no clever exploit at all — just a default password, an exposed file, or a careless setting. We turn to security misconfiguration, the unglamorous category behind a huge share of real incidents.

⁂ Back to all modules