Cross-site request forgery
Cross-site request forgery is a web attack that induces an authenticated user’s browser to submit an unintended request to a trusted application.
Acing the Frontend Interview
Cross-site request forgery is an attack that tricks an authenticated user’s browser into sending an unintended request to a trusted site.
- How it is used
- Protects authenticated form submissions from unintended actions initiated by malicious third-party sites.
- How deep it goes
- Explains the attack and token-based defense but does not provide token-generation or validation code.
- Examples
- Uses an authenticated user tricked into submitting an unintended action as the attack scenario.
- What you can do after
- Operate/configure it by adding server-generated hidden anti-CSRF tokens and validating them on every form submission.
Read how Acing the Frontend Interview explains cross-site request forgery →
ASP.NET Core in Action, 3e
Cross-site request forgery (CSRF) is an attack in which a victim's authenticated browser is induced to submit an unintended request to a trusted application.
- How it is used
- Protects cookie-authenticated applications from unintended requests submitted through a victim’s browser.
- How deep it goes
- Explains the forged-request and two-token mechanisms, automatic Razor Pages protection, and ways to disable it.
- Examples
- Uses a forged bank-transfer form and a generated hidden verification field to illustrate the attack and its protection.
- What you can do after
- Apply protection via Razor Pages by retaining generated tokens and validation, and recognize the risks of disabling them.
Read how ASP.NET Core in Action, 3e explains cross-site request forgery →
Spring Security in Action, Second Edition
Cross-site request forgery is an attack that causes a user's authenticated browser to send an unintended state-changing request to a web application.
- How it is used
- Protects authenticated web applications from forged state-changing requests and explains when Spring Security's default protection applies.
- How deep it goes
- Explains the attack, token flow, filter integration, request testing, and extension contracts, while stopping short of broader attack theory.
- Examples
- Uses a file-management attack scenario, a Spring REST /hello endpoint, custom token logging, and curl requests.
- What you can do after
- Operate/configure Spring Security protection, test token-protected POST requests, and customize token handling through named contracts.
Read how Spring Security in Action, Second Edition explains cross-site request forgery →
Grokking Web Application Security
Cross-site request forgery is a web attack that causes a user's browser to send an unintended authenticated request to a site.
- How it is used
- Frames CSRF as a browser-based threat to authenticated user actions and a reason to protect state-changing endpoints.
- How deep it goes
- Explains CSRF through a GET comment-worm scenario and gives practical defenses, without detailing antiforgery-token implementation.
- Examples
- Uses a baking-forum GET comment form, a shortened redirect link, a self-replicating worm, and sensitive actions such as payments and deletions.
- What you can do after
- Apply it by keeping GET side-effect-free, using antiforgery tokens, and setting SameSite on sensitive cookies.
Read how Grokking Web Application Security explains cross-site request forgery →
Django in Action
Cross-site request forgery is a web attack that tricks an authenticated user’s browser into submitting an unintended state-changing request to a site.
- How it is used
- Protects Django forms that submit user actions, especially state-changing POST requests.
- How deep it goes
- Explains the attack, token flow, middleware check, and rejection condition without detailing middleware internals.
- Examples
- Uses a malicious comment-like form whose hidden fields secretly request a password change.
- What you can do after
- Apply it via Django’s {% csrf_token %} tag so submitted forms carry a value Django can validate.
Read how Django in Action explains cross-site request forgery →
Secure APIs
Cross-site request forgery is an attack in which a victim's authenticated browser is induced to send an unintended request.
- How it is used
- Protects OAuth authorization flows from malicious requests that exploit an authenticated identity-provider session.
- How deep it goes
- Traces the attack through authorization, redirection, and token exchange, then gives state and redirect-URI mitigations.
- Examples
- Uses malicious links, authorization URLs, active IdP sessions, redirect URIs, authorization codes, and access-token exchanges.
- What you can do after
- Apply state validation and constrained redirect URIs to reduce authorization-code and access-token hijacking.
Also covered in
- Software Security for Developers
- Pro ASP.NET Core 7, Tenth Edition
- Spring in Action, Sixth Edition
- The Well-Grounded Python Developer: How the pros use Python and Flask
What to know first
- cookieAn HTTP cookie is a small piece of data stored by a client and sent with subsequent requests within its scope, often to maintain state or preferences.
- sessionA session is a bounded interaction or execution context associated with a user, client, process, or service that groups related exchanges or operations and may retain state.
- HTTP requestAn HTTP request is a message sent by a client to a server using the Hypertext Transfer Protocol, specifying a method and target and optionally including headers and a body.
- HTTP methodAn HTTP method is a standardized token in an HTTP request that indicates the operation the client intends to perform on a resource.
Related concepts
- CSRF tokenaddressed by · A CSRF token is an unpredictable server-issued value required on state-changing requests to verify that they originated from the intended application.
- csrf protectionaddresses · CSRF protection is a web security mechanism that prevents forged state-changing requests from an authenticated user's browser from being accepted.
- state parameteraddressed by · A state parameter is an opaque client-generated value carried through an authorization exchange to bind the response to its initiating request and help prevent request forgery.
- vulnerabilitykind of · A vulnerability is a weakness or condition that makes a system, person, or group susceptible to exploitation, compromise, or other harm.
- cross-site request forgery protectionaddressed by · Cross-site request forgery protection is a web-security technique that prevents unauthorized requests made on behalf of an authenticated user.
- Proof Key for Code Exchangeaddressed by · Proof Key for Code Exchange (PKCE) is an OAuth security extension in which a client proves possession of a per-request secret when exchanging an authorization code.
Questions about cross-site request forgery
What is cross-site request forgery?
Cross-site request forgery is a web attack that induces an authenticated user’s browser to submit an unintended request to a trusted application.
Which Manning books explain cross-site request forgery?
Acing the Frontend Interview, ASP.NET Core in Action, 3e, Spring Security in Action, Second Edition, Grokking Web Application Security, Django in Action and Secure APIs.
What should I know before learning cross-site request forgery?
Manning books that teach cross-site request forgery usually introduce cookie, session, HTTP request and HTTP method first.
What is cross-site request forgery a kind of?
Cross-site request forgery is a kind of vulnerability. A vulnerability is a weakness or condition that makes a system, person, or group susceptible to exploitation, compromise, or other harm.
What is cross-site request forgery also called?
Cross-site request forgery is also called CSRF.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.





