iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up
« Previous

CSRF HOME

Welcome to the iwantcoding.com CSRF Tutorial. CSRF tricks a logged-in browser into doing something the user didn’t intend. SameSite cookies, anti-forgery tokens, and Origin checks are the defences — here’s how to wire them correctly.

What this tutorial covers

ChapterYou will learn
CSRFHow it works, ambient authority, classic form, JSON / API, login CSRF, safe demo lab.
PreventionSynchronizer tokens, double-submit cookies, SameSite, Origin / Referer checks, CORS preflight, framework defaults, SPAs & JWT vs cookies.
DetectionCode review, automated tests, anomaly monitoring.
ExamplesCheatsheet, runnable snippets, quiz, exercises, bootcamp, certificate.

Who this is for

  • Backend devs writing state-changing endpoints.
  • AppSec engineers reviewing auth flows.
  • SPA devs choosing between cookies and bearer tokens.
How to use this tutorial: read the chapter, run the example with Try it Yourself », do the exercise, then take the quiz at the bottom. Hit Mark complete when you're done — the sidebar will track your progress.

Example

Example
// VULNERABLE: cookie auth + no CSRF defence
app.post('/transfer', requireAuth, (req, res) => transfer(req.body));
// SAFE: SameSite=Lax cookies + synchronizer token + Origin check
app.use(cookieSession({ sameSite: 'lax', secure: true, httpOnly: true }));
app.use(csrfProtection);
Try it Yourself »

Discussion

Loading…

« Previous