> 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/de/web/dom/dom-based-cookie-manipulation.md).

# DOM-basierte Cookie-Manipulation

Notizen zur DOM-basierten Cookie-Manipulation für Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungs-Workflow, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### DOM-basierte Cookie-Manipulation

Dieses Lab zeigt eine clientseitige Manipulation (DOM) von Cookies, die es ermöglicht, einen Wert in das `lastViewedProduct` Cookie einzuschleusen. Das Ändern dieses Werts kann eine Codeausführung (XSS) auf einer anderen Seite verursachen und die `print()` Funktion aufrufen. Die Ausnutzung erfolgt, indem das Opfer über den Exploit-Server zu den erforderlichen Seiten weitergeleitet wird.

* Es gibt ein Sitzungscookie mit dem Namen `lastViewedProduct` das den Link zum zuletzt angesehenen Produkt enthält.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-36d2d0540f1e3c9731099d4edd90921822f63955%2F%7B472575CE-A517-4CD9-8FBF-39B54F2C26C8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Auf der Seite gibt es einen Abschnitt „Zuletzt angesehenes Produkt“ mit einem Anker wie `&lt;a href=".../product?productId=1"&gt;Zuletzt angesehenes Produkt&lt;/a&gt;`.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a494448d2178add2f3fd791944cbf8f2ad114f0%2F%7BAB74DE1F-9DE5-4422-8703-CF2DE098F4C0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Durch das Ändern des als „zuletzt angezeigte Seite“ gespeicherten Werts kann der angezeigte Link als HTML/JS interpretiert werden.
* Durch Ersetzen des Cookie-Werts durch eine externe URL (`https://jord4n.pro`) leitet der Link zu dieser Website weiter.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bb2d1a3728f0e27028f867c7ca64d8befae12a0f%2F%7B4B4BBFEA-AF87-4629-B241-2623CF31F710%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Die Einfügung von `JavaScript:print()` in den Wert wird vom Browser in diesem Kontext interpretiert.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a18c40aa02357f1c4565c736da9b624e273d13ee%2F%7BBEE27B3D-6CE4-443D-A42D-9C8045F1087B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Durch das Einschleusen eines Payloads mit HTML, zum Beispiel `productId=1&'><h1>TEST</h1>`, wird der Inhalt gerendert.

{% code overflow="wrap" %}

```html
&lt;a href="https://0a73004204b35bb980b9218200c90043.web-security-academy.net/product?productId=1"&gt;Zuletzt angesehenes Produkt&lt;/a&gt;
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0e3b88951a0b1f8f2b876bf32cad1ca341c967ff%2F%7B300C232B-B69B-413A-9A59-184840499D71%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Ein Skript-Payload wie `productId=1&'><script>print()</script>` wird ebenfalls interpretiert und ausgelöst `print()`.

```
productId=1&'><script>print()</script>
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dfbb4ff2d46f45101875487647e5c3efe8ac0b8c%2F%7B9AFEBFB1-F361-4A70-80D1-1A4716ABB890%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. Speichere beim Opfer in seinem `lastViewedProduct` Cookie einen Wert, der die Injektion enthält (die Produktseite wird verwendet, um diesen Wert zu speichern).
2. Leite das Opfer dann zur Startseite (oder zur Seite, die „Zuletzt angesehenes Produkt“ anzeigt) weiter, sodass der fehlerhaft formatierte Wert zurückgegeben wird und das Skript ausgeführt wird (`print()`).
3. Verwende den Exploit-Server, um die Weiterleitung zur Produktseite (die das Cookie schreibt) und anschließend zur Seite, auf der das Cookie angezeigt wird, zu orchestrieren.

{% code overflow="wrap" %}

```javascript
<iframe src="https://0a73004204b35bb980b9218200c90043.web-security-academy.net/product?productId=1&'><script>print()</script>" onload="if(!window.x){this.src='https://0a73004204b35bb980b9218200c90043.web-security-academy.net/'; window.x=1;}"></iframe>
```

{% endcode %}

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b109e12396eb114e843e97d8f606e98c19d2ed46%2F%7B9257C3B5-3544-4697-9B4B-C2DBA4B0441E%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/de/web/dom/dom-based-cookie-manipulation.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.
