> 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/xss/dom-xss-document-write-with-location-search.md).

# XSS DOM document.write avec location.search

### XSS DOM dans le point d'injection document.write utilisant la source location.search

Ce labo contient une vulnérabilité DOM de type XSS dans la fonctionnalité de suivi de la requête de recherche. La page utilise `document.write` pour écrire des données provenant de `location.search` dans le DOM, qui peut être contrôlé via l'URL.

**Description de la vulnérabilité**/ `document.write` est appelée avec la `location.search` chaîne sans assainissement. Comme l'entrée provient directement de l'URL, un attaquant peut injecter du HTML/JS dans la page en manipulant `location.search`.

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

**Objectif de résolution** Réalisez une attaque XSS côté DOM qui appelle la `alert()` fonction lors du chargement de la page.

**Commentaires/indices**/ Le code génère quelque chose comme une `<img>` balise contenant un `searchTerms` paramètre entre guillemets, par exemple :

```html
<img src="/resources/images/tracker.gif?searchTerms=Jordan">
```

<figure><img src="/files/811fc38ada7b283e09ef8705d4677f6166f82f37" alt=""><figcaption></figcaption></figure>

Si vous fermez la `<img>` balise et les guillemets, vous pouvez insérer du contenu HTML/JS arbitraire.

**Exemples de charges utiles testées (fournies)**/ Fermez la balise et injectez du HTML :

```html
"><h1>hack</h1>
```

<figure><img src="/files/4fc2e7f2207c658866de08dd576603a06bf25ad2" alt=""><figcaption></figcaption></figure>

Fermez la balise et injectez un script pour déclencher `alerte`:

```javascript
"><script>alert("xss")</script>
```

<figure><img src="/files/7fe72aae7aac9e1259118628295cdb3349a1a8ed" 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/fr/web/xss/dom-xss-document-write-with-location-search.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.
