Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Why is a GET endpoint that deletes a resource (e.g. GET /delete?id=123) especially dangerous with respect to CSRF?
💻 Code Challenge | +75 XP
Add csurf middleware to an Express app protecting a POST /transfer route, and render the CSRF token into the corresponding form template.
A payment transfer form is being rejected with an "invalid csrf token" error after the fix was deployed, but worked before. Reorder the steps to diagnose the likely cause.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Implementing a state-changing operation as a GET request
// Wrong: triggerable by a simple <img> tag anywhere
app.get("/account/delete", deleteAccount);
// Correct: requires a real form submission or fetch call
app.delete("/account", deleteAccount);The Solution //
A GET request can be triggered automatically by an <img>, <link>, or <script> tag with zero user interaction — making any state-changing GET endpoint trivially exploitable via CSRF. All mutating operations must use POST, PUT, PATCH, or DELETE.
The Error //
Relying solely on CORS configuration to prevent CSRF
// CORS alone does NOT stop this classic CSRF vector:
<form action="https://victim-api.com/transfer" method="POST">...</form>
// The form submits regardless of CORS headersThe Solution //
CORS controls which origins can read a cross-origin response via JavaScript — it does not prevent a browser from sending a cross-origin request with cookies attached in the first place (like a plain HTML form submission), which is exactly the mechanism CSRF exploits. CORS and CSRF protection solve different problems and both are needed.