> 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/web/cache-poisoning/cache-poisoning-with-an-unindexed-header.md).

# Cache Poisoning with an Unindexed Header

Cache Poisoning with an Unindexed Header notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Web Cache Poisoning with an Unkeyed Header

This application is vulnerable to a **web cache poisoning** because it deals dangerously with an entry from a **unkeyed header**. / A legitimate user regularly visits the home page of the site.

\*\* Target:\*\*/ Poison the cache so that the home page serves a response that executes `alert(document.cookie)` in the victim's browser.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-50eb40c0f26dfcc9e2a7d5f3ede2f1e6cf6e193b%2F%7B179229EB-5D9E-4D9E-9E35-A159EA43085D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1246134e492a74184e7d0933947f57b47b69a418%2F%7B94CD8715-1AD2-4EB7-AE7E-E0C9197F1B02%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analysis of cache behavior**

* When intercepting the query to the main page, a **`Age`** parameter is observed in the response, indicating that the resource is cached for **30 seconds**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-51e013f8a9bff021c611c09e3aba011069bb488f%2F%7B5DAC2C14-2A32-4CFE-8F47-6E17F6E5FECD%7D.png?alt=media" alt="" width="481"><figcaption></figcaption></figure>

* Adding an arbitrary parameter to the URL, for example `?test=1`, shows that:
* The cache key is regenerated.
* The cached content can be modified and served to other users during the cache.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1b4f3129e2b3109984b1ac37dcaf9b9227e64e8b%2F%7BDBC5E9F6-DCA1-4066-8943-C3B3ACBD6D6B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

If one manages to poison the root response (`/`), any visitor will see this malicious content during these 30 seconds

**Search for exploitable headers**

* Using **Param Miner** in Burp Suite:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad226c0c8646b5d405526a186b1ba38af28038f7%2F%7BC15DCB8F-20F5-4081-B4B2-2C2F88B30A2D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Since the **Repeater**, the function **Guess headers** is used.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-340e57e83f64f71c40e9747721f485d730a36e2e%2F%7BB56C9431-84E0-4335-978B-95908B200558%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1141358c26e17d2ca6fec568a41ae3a39900516e%2F%7B84E094DC-FDF5-4026-A9C8-1FB27790F06D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

The extension detects a poisoning behavior of the header-bound cache **`X-Forwarded-Host`**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-371e9b7bbd868c090ae55b3c68af0f02358be8db%2Fimage%20(245).png?alt=media" alt=""><figcaption></figcaption></figure>

**Unindexed header operation**

* The following heading is added to the request:

```http
X-Forwarded-Host: test.com
```

* The answer then includes a loading of JavaScript resource from this domain.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8bac1ec4fba20168496038a7c26134ee819e04af%2F%7B25847D5E-3B24-4BEF-8549-7390163BBDD4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* When reloading, the application always tries to retrieve this script, which confirms that the answer is cached.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1e5b1537966fc4be8c981a2e9f6e00cbb2a5e965%2Fimage%20(246).png?alt=media" alt=""><figcaption></figcaption></figure>

**Redirect to the operating server**

* The header value is replaced by the operating **server domain**:

```http
X-Forwarded-Host: exploit-0a1c0025035a473c807ce8e901e3001a.exploit-server.net
```

The application then seeks to load the following resource:

**Malicious Payload Injection**

* On the operating server, you create the file:

```javascript
/resources/js/tracking.js
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-785eb9a83861e50f3e9ef2732a8811a072a4dada%2F%7B34CE6099-2EAE-4767-A58C-6CAE0DCC8D77%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

File Content:

```javascript
alert(document.cookie)
```

* This script is now included in the cached answer.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5eb5902cf86b64a56ae7a3ac3eb4e0917eac6c4e%2F%7B679B2E9B-86AD-486E-9DFD-E24382708011%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Result**

* When a user visits the home page during the cache validity period:
* The browser loads the poison script.
* A dialog box appears with `document.cookie`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87048244cd53151479258da4ca89ebfaa0ab3266%2F%7B6D7693AA-3695-46B7-B5D2-5FDD2B4B5DE7%7D.png?alt=media" 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 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/web/cache-poisoning/cache-poisoning-with-an-unindexed-header.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.
