🔍 What is CSRF?

CSRF (Cross-Site Request Forgery) is a web vulnerability that tricks a user into unknowingly submitting a malicious request on a web application where they’re already authenticated. It exploits the trust that the application has in the user's browser, not the user’s trust in the site.

📌 Key Concepts

🚀 Attack Flow

  1. User logs into a target website (e.g., bank.com)
  2. Session is maintained via a cookie
  3. User visits an attacker-controlled site
  4. That site auto-submits a form to bank.com using the existing session
  5. The action executes without the user's consent

💣 Real-World Example: CSRF in Password Change

If the following endpoint changes a password without CSRF protection:

POST /change-password HTTP/1.1
Host: vulnerable-site.com
Content-Type: application/x-www-form-urlencoded
Cookie: session=abc123

newPassword=hacked123

An attacker could craft a malicious HTML page:

<html>
  <body onload="document.forms[0].submit()">
    <form method="POST" action="https://vulnerable-site.com/change-password">
      <input type="hidden" name="newPassword" value="hacked123" />
    </form>
  </body>
</html>

If a logged-in user visits the attacker’s page, their password will be silently changed. No JavaScript from the attacker is required!

🕵️‍♀️ How to Detect CSRF

🛡️ Prevention & Mitigation

🛠️ Tools for Testing CSRF

💡 Practical Tips