Cyberlium
Cyberlium
Cyberlium on Android·Google Play Store

Learn cybersecurity with hands-on labs and AI mentor support on your phone.

Mod 6 · Les 2/5
In progress
Module 6•Lesson 2 of 5•⏱️ 15 min read•Beginner+39 XP

CSRF Basics

Cross-site request forgery defense — tokens and SameSite on YOUR lab forms.

CSRF Basics
00:00/02:40

Visual · t17_csrf_basics

CSRF = browser sends authenticated request user did not intend. Original Cyberlium.

Your browser will happily POST a transfer if the session cookie still works — CSRF defenses say prove intent.

CSRF tricks a logged-in browser into submitting state-changing requests to YOUR app using the victim's existing session. Defenses: unpredictable anti-CSRF tokens validated server-side, SameSite cookies, double-submit or custom headers for AJAX, and re-auth for sensitive actions. Learn to spot missing CSRF on forms in $REPO — never deploy CSRF PoCs against classmate, employer, or public production apps without written scope.

1. Attack shape

Attacker page triggers POST/PUT/DELETE while victim session is active — browser attaches cookies automatically.

Safe methods (GET) should not change state — defense starts with HTTP semantics.

Command guide

Try these commands — Attack shape

═══ LINUX / BASH (Network & Reconnaissance Audit) ═══

Scan target host for open ports and service version signatures

Command — copy this

nmap -sS -sV -p 80,443,8080 -Pn ${LAB_HOST:-127.0.0.1}

DNS and WHOIS reconnaissance on authorized domain

Command — copy this

dig +short A target.local
dig +short MX target.local
whois target.local 2>/dev/null | grep -iE "(Registrar|Creation Date|Name Server)" | head -6

Inspect HTTP headers for technology stack fingerprinting

Command — copy this

curl -s -I "http://${LAB_HOST:-127.0.0.1}:8080" | grep -iE "(Server|X-Powered-By|Set-Cookie|Content-Security-Policy)"

Primary tools to practice this lesson: python3, grep. Reference sites: CSRF (https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html); SameSite (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite). Run every command in the box — install first, then the usage lines — only on YOUR lab / program scope.

2. Defenses

Synchronizer token in form + server validation per session or request.

SameSite=Lax/Strict reduces cookie inclusion on cross-site POSTs — not sole defense.

3. Lab boundary

Add or verify CSRF token on one $REPO state-changing form in dev.

No hosting fake pages that POST to stranger banking or school portals.

4. What you ship: CSRF defense notes

Attack one-liner + token defense + SameSite note + NEVER stranger CSRF PoC.

5. What you record before the next lesson

CSRF defense paragraph.

6. Wrong vs right: stranger apps vs YOUR repo

Worked failure — same MSF word, opposite target. Right never needs a café Wi-Fi or classmate laptop.

  • Wrong: Host CSRF demo against employer HR portal without ticket.
  • Right: Name CSRF defenses. Next: OAuth roles.
Hands-on Exercise

Mission: CSRF defense draft

1) Explain CSRF in one sentence. 2) Name two defenses. 3) Write NEVER CSRF PoC on stranger apps.

Pro Tip

Stuck? Ask Cyberlium AI Mentor

Ask Mentor: “Token per session vs per form?”

Practice QuizQuestion 1
Multiple choice
Q1

APPLY: CSRF exploits:

Practice QuizQuestion 2
True or False
Q2

APPLY: True or False: CSRF PoCs on production strangers is homework.

Practice QuizQuestion 3
Multiple choice
Q3

APPLY: Strong CSRF defense includes:

←Previous: Session Hygiene
Answer 3 practice quiz questions to unlock XP reward. (0/3 answered)
Skip quiz & read next →