CSRF exploits trust that a website has in the user's browser and existing authentication.
How CSRF works
- Victim is authenticated to vulnerable site (has session cookie).
- Attacker tricks victim into visiting malicious page.
- Malicious page makes request to vulnerable site.
- Browser automatically includes session cookie.
- Vulnerable site processes request as legitimate user action.
Attack examples
- Transfer money from victim's bank account.
- Change account email or password.
- Post content or comments as victim.
- Delete user data or resources.
- Add/remove admin users.
Attack vectors
- Malicious websites with hidden forms.
- Image tags with action URLs:
<img src="bank.com/transfer?to=attacker&amount=1000"> - Iframe embedding vulnerable endpoints.
- Malicious browser extensions.
- XSS combined with CSRF.
Prevention
- CSRF tokens: Random, unique per-session tokens in forms.
- SameSite cookies: Prevent cookie sending on cross-site requests.
SameSite=Strict: No cross-site cookies (most secure).SameSite=Lax: Allow safe methods (GET) only.SameSite=None: Requires Secure flag (HTTPS only).
- Origin/Referer validation: Check request source headers.
- Custom request headers: Require X-Requested-With or similar.
- Double submit cookies: Compare cookie value with form value.
- Re-authentication: Require password for sensitive actions.
Testing
- Remove CSRF token and submit form.
- Change token to invalid value.
- Use token from different session.
- Test cross-origin requests with different SameSite values.
Impact
- Unauthorized state changes.
- Account takeover.
- Financial loss.
- Data modification or deletion.
- Reputation damage.
Related Articles
View all articlesHow to Extract and Analyze Cookies from Your Browser
Learn how to view, export, and analyze HTTP cookies from Chrome, Firefox, Edge, and Safari using browser DevTools. Includes security analysis tips.
Read article →PCI DSS Compliance Validation Workflow
Complete guide to PCI DSS 4.0.1 compliance validation from merchant classification through SAQ completion. Covers cardholder data environment mapping, network segmentation, encryption validation, vulnerability scanning, and policy implementation.
Read article →Secure Password & Authentication Flow Workflow
Master the complete secure password and authentication workflow used by security teams worldwide. This comprehensive guide covers NIST 800-63B password guidelines, Argon2id hashing, multi-factor authentication, session management, brute force protection, and account recovery with practical implementation examples.
Read article →What Should I Do if I Find Insecure Cookies on My Website?
Step-by-step remediation guide for fixing insecure cookie configurations, from adding security attributes to testing implementations across frameworks.
Read article →Explore More Web Security
View all termsCORS (Cross-Origin Resource Sharing)
A browser security mechanism that controls how web pages can request resources from different domains, preventing unauthorized cross-site data access.
Read more →Cross-Site Scripting (XSS)
A web security vulnerability that allows attackers to inject malicious scripts into web pages viewed by other users.
Read more →HTML Entity Encoding
A method of representing special characters in HTML using named or numeric references to prevent interpretation as code.
Read more →HTTP Cookie
Small pieces of data stored by web browsers, used for session management, personalization, and tracking.
Read more →HTTP Security Headers
Response headers that enable browser security protections against common web attacks.
Read more →JSON Web Token (JWT)
A compact, URL-safe token format used to securely transmit claims between parties in web applications.
Read more →