What is CSRF and how is an application protected against forged requests?
Published on 2026-10-20 by frfrand
What is a CSRF attack, how it exploits session cookies, and how to protect an application with anti-CSRF tokens, SameSite, and origin verification.

Short answer: CSRF is an attack that exploits the fact that an authenticated person's browser sends their session cookies to a site to make them execute an action they did not want. It is defended by requiring something that another page cannot set, such as an anti-CSRF token or a custom header, along with SameSite cookies and origin verification.
It means Cross-Site Request Forgery, or falsification of requests between sites.
The key is that a website can recognize a session through cookies. An attacker tries to cause the browser to send an operation using that identity.
The example of an order you never gave
Imagine that you log into your bank and leave the session open. Then you visit an unknown page that tries to trigger a request to modify some data in your account.
If the bank accepted the operation solely because it arrived with a valid cookie, it could treat an unwanted action as if you had requested it. A correct design checks something more than "there is an active session."
It does not mean that any site can read your bank data: same-origin policy limits many reads between pages. Preventing reading a response and preventing a request from being sent are different problems.
What role do cookies play?
The browser can attach cookies to requests based on the domain, cookie policies, and browsing context. That convenience allows sessions to be maintained, but it also requires protecting sensitive actions.
Attributes such as SameSite help restrict when cookies are sent across sites. They are a useful defense, although they do not replace all server-side checks and require choosing a policy appropriate for the product.
What is an anti-CSRF token?
Many applications generate a value that the attacker should not know and require it to appear in operations that modify information. The server verifies that it corresponds to the expected session or context.
Frameworks such as Django include protections and verification mechanisms for forms and state-changing requests. But they still depend on correct configuration: disabling protections to "make the frontend work" can create a serious problem.
Does CORS solve CSRF?
No. CORS regulates certain cross-origin accesses from browsers, but it was not designed to replace an anti-CSRF defense. A request can produce effects on the server even when the browser does not allow reading its response.
It is also not advisable to confuse CSRF with XSS. In XSS, the attacker manages to execute untrusted code within the context of a page. Both problems can be related, but their causes and mitigations are different.
What operations need attention?
Changing a password, modifying an email, transferring funds, adding users, or deleting records are examples of actions whose legitimate origin must be verified.
GET requests, by convention, should not modify state. If visiting a URL triggers a deletion, in addition to possible CSRF, there is an incorrect HTTP design decision.
How to check protection?
Test that a legitimate form works and that an operation without the required token or context is rejected. Also check what happens when the session expires and when the request comes from an unexpected origin.
Do not perform security tests against third-party services without permission. A test environment of your own allows you to verify configurations without risking real data.
What does this mean in ArduMaker?
If you host on an ArduMaker VPS an application that uses session cookies, its backend must apply appropriate CSRF defenses. The fact of deploying it under HTTPS does not automatically eliminate that risk.
A detail with Django: in ArduMaker, HTTPS is handled by the host's nginx and your application receives the request already decrypted, through a proxy. Add your domain with https:// to CSRF_TRUSTED_ORIGINS and check what value of X-Forwarded-Proto reaches the application before configuring SECURE_PROXY_SSL_HEADER. Disabling CSRF protection so that the form works is not the solution.
In short: CSRF attempts to turn a legitimate user's session into an operation they did not authorize. Defense requires validating the intent of the request, in addition to the identity.
Frequently asked questions
Does SameSite suffice to prevent CSRF? It helps a lot, especially with Lax or Strict, but it does not cover all cases (subdomains of the same site, old browsers, GET actions). It is advisable to combine it with tokens or with origin verification.
Does an API with tokens in the Authorization header need CSRF protection? Generally no, because the browser does not add that header on its own. The risk appears when authentication travels in cookies.
Related: What is CORS · What is XSS.
Sources: OWASP CSRF Prevention Cheat Sheet · Django CSRF Protection.
