> 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/cache-poisoning/web-cache-poisoning-with-unkeyed-cookie.md).

# Cache poisoning com um cookie não chaveado

### Envenenamento de cache web com um cookie não incluído na chave

Este laboratório é vulnerável a envenenamento de cache web, pois os cookies não estão incluídos na chave do cache. Um usuário legítimo visita regularmente a página inicial. / O objetivo é envenenar o cache com uma resposta que executa `alert(1)` no navegador da vítima.

#### Análise da resposta

* A requisição é interceptada para a raiz (`/`).
* Na resposta HTML, observamos um script JavaScript contendo dados dinâmicos:

```javascript
<script>
  data = {
    "host":"0ab5006d03269ea785b94a9e000100c5.web-security-academy.net",
    "path":"/",
    "frontend":"prod-cache-01"
  }
</script>
```

* O `frontend` é o valor de um cookie enviado pelo navegador

#### Observação do cookie

* Na solicitação, um cookie chamado `fehost` está presente:

```bash
fehost=prod-cache-01
```

* Esse valor é reutilizado diretamente na resposta sem ser integrado à chave do cache.

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

#### Manipulação de cookies

* Ao alterar o valor do `fehost` cookie, a resposta reflete imediatamente o novo valor:

```bash
fehost=test
```

* Isso confirma que o cookie **não é indexado no cache** e que ele influencia o conteúdo em cache.

<figure><img src="/files/957fe8b5058af4fd4503e2c693d53643c35b71be" alt=""><figcaption></figcaption></figure>

#### Injeção de payload

* Em seguida, um valor malicioso é injetado no cookie para quebrar o contexto JavaScript e executar código arbitrário:

```javascript
test"-alert(1)-"efffe
```

<figure><img src="/files/19b1ee47f80ed69b212743e2995ea6cab86f21f9" alt=""><figcaption></figcaption></figure>

* O payload sai da string JavaScript e injeta uma chamada para `alert(1)`.

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


---

# 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/cache-poisoning/web-cache-poisoning-with-unkeyed-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.
