← Cross-Site Request Forgery lesson
IdentityCross-Site Request ForgeryIntermediate30 min+150 XP

MFA Off Switch

The disable mfa endpoint in this account application changes state over GET and relies only on a SameSite=Lax cookie. Make the victim bot load the attacker page and perform the action.

“The bank saw a perfect request. The customer never made it.”

CWE-352OWASP Top 10 A01:2021OWASP ASVS 4.2.2
The story
A browser attaches cookies to requests, not intentions. Ask whether a state-changing endpoint can distinguish a real user action from a forged one.

Cookies are ambient authority: the browser sends them automatically to the cookie's host. If a state-changing endpoint relies only on that cookie, another site can cause the request without reading the response. The server authenticates the browser, not the human.

Your objective
  • Inspect the account action endpoint
  • Build a cross-site request on the attacker origin
  • Report the attacker URL to the victim bot
  • Capture the flag
Boundary under test

Browser cookie to server session

Field guide · request anatomy

Where to look before you type a payload

01Victim session

The victim is signed in and the browser holds a session cookie for the target site.

02Attacker page

The attacker hosts a page, image, form or navigation that targets the victim site.

03Automatic credentials

The browser attaches cookies according to host and SameSite rules; the attacker does not need to read them.

04State change

The endpoint accepts the request without proving user intent, so the server performs the action.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Find the account action that changes state.

Hint 2

Notice whether the endpoint uses GET and only a session cookie.

Hint 3

The action is a GET and SameSite=Lax still sends the cookie on top-level navigation. Report the attacker URL with endpoint=/account/mfa, enabled=false.

Hint 4 · near the answer

Report the attacker URL with the endpoint, parameter and target value.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — MFA Off Switch

- Family: Cross-Site Request Forgery
- Lab ID: web-csrf-mfa
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "MFA Off Switch" and record /account/mfa, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects /account/mfa, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: Report the attacker URL with endpoint=/account/mfa, param=enabled and value=false. The bot's navigation carries the Lax cookie.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: the /account/mfa GET action.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • The endpoint returns 403 to a cross-site form: verify whether the token is actually validated or only present.
  • The UI hides the action: the endpoint may still accept a direct request.
  • SameSite=Strict blocks the request in one browser: test top-level GET, older clients and alternate flows.

Regression tests to name

  • Cross-site GET: The request is rejected or the method is not allowed
  • Missing token: The server rejects it before the update
  • Wrong origin: The server rejects the request
The defender's move
  • Use non-idempotent methods and a per-session, unpredictable synchronizer token.
  • Validate Origin and Fetch Metadata on state-changing requests.
  • Set session cookies SameSite=Lax or Strict and never use GET for state changes.
  • Require re-authentication for high-impact actions.
See the secure-code pattern and all 4 regression tests →
الخلاصة

CSRF ليست سرقة جلسة، بل استغلال ثقة المتصفح: الكوكي تُرسل تلقائيًا. الحل ليس إخفاء النموذج، بل رمز مزامنة غير قابل للتخمين، وفحص المصدر، ومنع تغيير الحالة عبر GET.