Join our Newsletter — 33% off our NHI Course
Home› FAQ› Threats, Abuse & Incident Response› How do you test Cross-Site Request Forgery Prevention?
Threats, Abuse & Incident Response

How do you test Cross-Site Request Forgery Prevention?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 20, 2026 Domain: Threats, Abuse & Incident Response

You test Cross-Site Request Forgery Prevention by replaying state-changing requests without a valid anti-CSRF token or equivalent proof and confirming they are rejected. Check that the application ties the request to the user’s session, does not accept forged cross-site submissions, and protects all unsafe actions. Also confirm cookie settings and origin checks are consistent with the chosen defence model.

What a CSRF test is really proving

A meaningful CSRF test is not just “can I trigger the form from somewhere else?” It is proving that the server only accepts a state-changing request when it carries the anti-forgery evidence the application expects, and that the request is bound to the right user context. The check should cover forms, JSON endpoints, and any action that changes data, access, or state.

That means the test should follow the application’s defence model, not a single pattern. Some systems rely on synchroniser tokens, some on double-submit cookies, and some on origin or referer validation plus strict cookie behaviour. A good test confirms the chosen model is enforced consistently across the full request path, including edge cases such as partial submissions, alternate content types, and legacy endpoints.

For a structured way to exercise the right request paths and expected outcomes, use the OWASP Web Security Testing Guide as a companion to your own application-specific test cases.

How to validate the defence is actually enforced

Start by capturing a legitimate state-changing request, then replay it without the anti-CSRF token, with a stale token, and with a token taken from a different session. The application should reject each attempt, ideally with a clear failure mode that does not perform the underlying action. Repeat the same checks against the most important unsafe operations, because CSRF gaps often appear only on a subset of routes.

Next, verify the request is tied to the authenticated session in the way the design intends. If the app uses a token stored in the browser, confirm it is not reusable across users or sessions. If it relies on origin checks, confirm the server rejects cross-site requests when the Origin or Referer does not match the expected site. If it depends on cookie flags, check that the session cookie is not sent in a way that undermines the defence.

The practical test is to prove the control fails closed. If the request still succeeds after the token is removed, altered, or replayed from an external context, the defence is incomplete even if the UI appears protected.

The OWASP Cheat Sheet Series is useful here because it gives implementation detail for session handling, token handling, and related browser-side controls that your test should reflect.

What usually escapes basic CSRF testing

Basic form tests miss the endpoints that matter most in real applications: JSON APIs, mobile back ends, admin functions, password or email change flows, and one-click actions hidden behind “convenience” features. They also miss cases where one endpoint is protected while a related endpoint is left open, which gives an attacker a different path to the same state change.

Another common blind spot is inconsistent browser behaviour. Cookie attributes, same-site settings, custom headers, redirects, and CORS assumptions can all affect whether a forged request is actually possible. A control that works in a lab with one browser or one route may still fail in production if a different request shape is accepted or if an alternate domain can reach the same action.

Coverage should therefore be broader than the obvious form submission. If the application exposes multiple ways to perform the same business action, each path needs the same anti-CSRF treatment or an equivalent protection.

Risk and Threat Considerations

CSRF matters because the attacker does not need the victim’s password if the browser will automatically carry the victim’s session into a forged request. The exposure is highest on actions that change account data, transfer value, alter access, or weaken later security controls.

Failure mechanism: The application accepts a cross-site request as if it were user initiated, usually because the token is missing, not validated, not bound to the session, or bypassed on a secondary endpoint. Weak cookie settings or absent origin checks can make that failure easier to trigger.

Impact: An attacker can silently perform state-changing actions in the victim’s account, potentially leading to configuration tampering, privilege-related changes, data exposure, or account takeover follow-on steps. The risk is not limited to classical HTML forms; any unsafe action reachable with ambient browser credentials is in scope.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 addresses the attack and risk surface, while OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP ASVSV10 — OAuth and OIDCCSRF testing often validates anti-forgery handling in login and token flows.
V7 — Session ManagementCSRF defences depend on session binding, cookie behaviour, and request context.
V8 — AuthorizationCSRF can trigger unauthorized state changes even when authentication is intact.
Recommendation — Test that OAuth and OIDC flows use the correct anti-CSRF state protections. Verify that session cookies and request handling prevent cross-site action replay. Confirm unsafe actions require the intended user context before execution.
NIST SP 800-53 Rev 5IA-2 — Identification and Authentication (Organizational Users)User session authenticity is central to preventing forged state-changing requests.
AC-6 — Least PrivilegeCSRF impact grows when sessions can perform more actions than necessary.
Recommendation — Ensure organizational user sessions cannot be impersonated by cross-site requests. Limit account privileges so forged requests cannot cause broader harm.
OWASP Non-Human Identity Top 10NHI-10 — Human Use of NHIThe CSRF defence model often depends on humans not reusing browser-held secrets across contexts.
Recommendation — Prevent humans from reusing secrets or session context in ways that weaken request integrity.
CIS Controls v8CIS-6 — Access Control ManagementCSRF testing validates that access-controlled actions cannot be invoked without proper request checks.
Recommendation — Verify that access-controlled actions require the expected request-level protections.

Practitioner Guidance

What to verify: Test the highest-value unsafe actions first, then confirm every alternate route to the same business function uses the same protection. A route is not “covered” just because the main form is covered.

Common mistake: Teams often test only with a missing token and stop there. You also need replay, session-switch, and cross-origin negative tests, because many real failures come from validation that is present but not actually tied to the right session or request context.

Practitioner takeaway: CSRF prevention is only trustworthy when you have proven the server rejects forged requests across every state-changing path, under the exact browser and session conditions the defence depends on.

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.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 20, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org