Use layered protection rather than a single safeguard. HTTPS should be the baseline, origin checks can block requests from unexpected sources, and Spring Security’s synchronizer token pattern adds request-level validation. Together, these controls make it much harder for a forged request to succeed, even if an attacker can trick a user into submitting a form or clicking a malicious link.
Why Spring CSRF defence should be layered, not single-control
CSRF protection in Spring-based applications is strongest when it combines transport security, request origin checks, and application-level token validation. Each layer blocks a different part of the attack path, so a forged request has to defeat more than one control. That matters because CSRF often succeeds by reusing a legitimate browser session rather than stealing credentials.
Spring Security already supports this layered model, and NHIMG’s CSRF Prevention Guide is a practical reference for token patterns, SameSite cookies, Fetch Metadata and framework settings. For teams standardising on Spring, the value is not a single feature toggle, but a coherent set of checks that line up with how browsers actually send requests.
HTTPS is the baseline because it protects the session cookie and the CSRF token in transit, but it does not stop a browser from making a cross-site request. Origin or referrer validation helps by rejecting requests from unexpected sources, while the synchronizer token pattern adds a secret the attacker cannot reliably read or replay from another site.
How the synchronizer token pattern fits into Spring Security
The synchronizer token pattern works by binding each state-changing request to a server-issued token that the browser must return. In Spring Security, this is the control that gives request-level validation, so forged form posts or script-driven submissions fail even when the user is already authenticated. That is why CSRF protection should be treated as a request integrity check, not just a cookie setting.
For browser-based applications, the token check is most valuable on state-changing actions such as form submits, profile updates and account changes. It is less about proving the user’s identity, and more about proving the request came through the application path you expected. NHIMG’s Spring Security Configuration Guide is useful when you need to audit filter-chain order, CSRF settings and deny-by-default behaviour together.
Spring teams should also understand where token-based CSRF protection can be weakened by implementation mistakes. If a token is leaked into logs, reflected responses, client-side storage or overly broad error handling, the attacker no longer needs to guess it. That is why the token mechanism must be paired with careful session handling and narrow exposure of security-sensitive data.
What to combine with CSRF tokens for a practical Spring defence
Origin checks, SameSite cookies and Fetch Metadata headers add useful defence in depth because they help block cross-site requests before the token check even runs. Origin validation is especially helpful for browsers that send a reliable Origin header on state-changing requests, while Fetch Metadata can reject cross-site traffic patterns that do not match normal same-site application behaviour.
When you are using Spring with browser sessions, a layered pattern is usually stronger than choosing one “best” control and assuming it covers every request path. NHIMG’s Fetch Metadata and Resource Isolation Policy Guide is a good companion when you want to formalise cross-site request rejection and fallback rules rather than depending on a single header or cookie attribute.
For teams that want broader Spring hardening context, NHIMG’s Java and Spring Security Guide helps place CSRF protection alongside filter chains, method security and other framework controls. That broader view matters because CSRF failures are often enabled by configuration drift, not by the token mechanism alone.
Risk and Threat Considerations
CSRF risk persists wherever a browser can automatically attach valid credentials to a request and the application trusts that request without enough context. The threat is not credential theft in the usual sense, but abuse of an existing authenticated session to perform actions the user never intended.
Failure mechanism: A malicious site or link causes the victim’s browser to send a same-session request to the Spring application, and the application accepts it because the request is authenticated but not sufficiently bound to origin, intent or a valid anti-CSRF token.
Impact: An attacker can trigger state changes such as account updates, profile modifications, preference changes or transaction-like actions, which can lead to fraud, unauthorised configuration changes or downstream account compromise.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the technical controls, while ISO/IEC 27001:2022 defines the regulatory obligations.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V4 — API and Web Service | CSRF protection is a web request integrity control for browser-facing application flows. |
| V7 — Session Management | CSRF depends on how browser sessions and cookies are issued and accepted. | |
| V8 — Authorization | CSRF can trigger unauthorised state changes by abusing an authenticated session. | |
| Recommendation — Require anti-CSRF validation on state-changing requests and verify it in web service tests. Bind session cookies and session state to secure browser handling and reject unsafe session reuse. Enforce server-side authorization checks on every sensitive action regardless of browser state. | ||
| NIST SP 800-53 Rev 5 | IA-2 — Identification and Authentication (Organizational Users) | CSRF exploits authenticated browser sessions, so authentication context remains central. |
| IA-5 — Authenticator Management | CSRF tokens and session credentials must be managed so they are not reusable or leaked. | |
| AC-6 — Least Privilege | Reducing privilege limits what a successful forged request can change. | |
| Recommendation — Ensure authenticated sessions are established and validated before any privileged action. Rotate and protect authenticators and related secrets so request forgery cannot replay them. Limit each session to the minimum permissions needed for the task. | ||
| ISO/IEC 27001:2022 | A.5.15 — Access control | CSRF defence supports controlled access to application functions and state changes. |
| A.8.24 — Use of cryptography | HTTPS is part of the layered CSRF defence because it protects session material in transit. | |
| Recommendation — Define and enforce access rules that restrict sensitive functions to intended users only. Use secure transport to protect session cookies and request secrets in transit. | ||
| CIS Controls v8 | CIS-6 — Access Control Management | CSRF defence reduces abuse of authenticated access paths. |
| Recommendation — Restrict access paths and verify that sensitive actions require explicit approval signals. | ||
Practitioner Guidance
What to prioritise: Protect every state-changing browser path first, then verify that your Spring configuration actually enforces the same CSRF policy across all relevant endpoints. If a route can change data and still works when the token is missing or stale, that route needs immediate attention.
What to verify: Confirm that your deployment blocks cross-site requests with more than one signal, and that exempted endpoints are tightly justified. Test real browser behaviour, not just happy-path unit tests, because CSRF mistakes often appear only when cookies, redirects and form submissions interact.
Practitioner takeaway: Treat CSRF defence as a layered request-validation problem, not a single Spring setting. The safest posture is one where origin context, browser behaviour and application tokens all have to line up before a state change is accepted.
Related resources from NHI Mgmt Group
- Guide: Web Application Attacks Guide
- How should security teams implement SAML-based single sign-on across enterprise applications without weakening authentication control?
- How should security teams implement Postgres RLS in multi-tenant applications without relying on it as the only control?
- How should security teams implement data loss prevention in AWS without relying on a single control?
- How should security teams implement role-based access control without creating role sprawl?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 5, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org