> 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

Notes sur le XSS DOM document.write avec location.search pour les laboratoires PortSwigger Web Security Academy, y compris le flux de travail d’exploitation, les tests de charge utile, la validation avec Burp Suite et le contexte de remédiation.

### XSS DOM dans le réceptacle document.write en utilisant la source location.search

Ce labo contient une vulnérabilité DOM de type XSS dans la fonctionnalité de suivi des requêtes de recherche. La page utilise `document.write` pour écrire des données provenant de `location.search` dans le DOM, ce 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="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-285c95883d25e18b3fd57703bb9cbfd4fadf1dfb%2F%7B71C2914B-1181-4283-97D9-BE369005ECA2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Objectif de résolution** Réalisez une attaque XSS côté DOM qui appelle la `alert()` fonction lorsque la page est chargée.

**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="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7015f343e74f8f00a9f988ac5d97d58733c3fbff%2F%7BD88B1544-A14A-483D-843A-87C3D304FE97%7D.png?alt=media" 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="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e990723f01026088e065e95c8ed8315f4f9d9273%2F%7B69F16E73-C94E-482E-B6AE-BAC849952B9E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1cb6a560a846ee995ffcdfa9f704d0c2e4fc1c2%2F%7B6656AD8C-DF1B-4935-AE99-1203574875DC%7D.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/fr/web/xss/dom-xss-document-write-with-location-search.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.
