Cross-Site Request Forgery (CSRF)
Definition
CSRF is a security vulnerability that tricks an authenticated user into executing unwanted actions on a web application where they are currently logged in. It exploits the trust a site has in the user's browser by forcing the browser to send unauthorized requests.
Where you hear it
- During security audits or code reviews. - When discussing web application authentication mechanisms. - While configuring security headers or middleware.
Examples
The application is vulnerable to CSRF because it lacks anti-forgery tokens.
We must implement CSRF protection on all state-changing endpoints.
The form includes a CSRF token, so a forged request from another site is rejected.
Common mistake
Confusing CSRF with Cross-Site Scripting (XSS). While XSS involves injecting malicious scripts into a page, CSRF focuses on forcing the user to perform unintended actions using their existing session credentials.
Don't confuse with
CSRF is often confused with Session Hijacking. While CSRF forces the victim's browser to perform an action on their behalf, Session Hijacking involves stealing the session token to impersonate the user entirely.
Say it at work
- In a meeting or chat
Did we remember to add the anti-forgery tokens to the new form, or are we leaving it exposed to CSRF?
- In an email or ticket
Please ensure that all state-changing API endpoints are protected against CSRF attacks before we merge this PR.