How can we prevent CSRF attack?

February 6, 2024 · By Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

We can prevent CSRF attack in two ways :

1. User Side Prevention:

  • Browsing Habits: Encourage users to browse one tab at a time, avoiding multiple tabs to reduce the risk of CSRF attacks.
  • Remember-Me Functionality: Suggest users not to use automatic login or “remember-me” features, as these may expose them to CSRF vulnerabilities.

2. Server Side Prevention:

  • CSRF Tokens:
    • What is it? A CSRF token is a unique string tied to a user’s session.
    • How it works: The server generates a token and sends it to the user’s browser, which stores it. The token is also stored on the server.
    • Submission: When a user submits a form or makes a request, the CSRF token must be included.
    • Validation: The server checks if the received token matches the one stored for that user’s session.

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion