Cross-Site Request Forgery (CSRF) Attack
What is CSRF?
CSRF attacks occur when a malicious website tricks a user's browser into making unintended requests to a trusted website where the user is authenticated. For example:
Since the user's browser includes the authenticated session cookies with the request, the bank's server might execute the malicious request unless additional protections are in place.
A CSRF token (Cross-Site Request Forgery token) is a security measure used to protect web applications from Cross-Site Request Forgery (CSRF) attacks.
领英推荐
Why is it effective?
The token ensures that a malicious site cannot craft a valid request because:
How does the CSRF Token help?
A CSRF token is a secret, unique, and unpredictable value generated by the server for each user session. It is included in forms or requests and validated by the server. Here's how it works:
CSRF Token vs SameSite Cookies
CSRF tokens can be used alongside the SameSite cookie attribute (e.g., SameSite=Strict or Lax), which also helps prevent cross-site requests by restricting cookies in cross-origin contexts.