> 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-with-innerhtml-and-location-search.md).

# XSS DOM avec innerHTML et location.search

Notes sur le XSS DOM avec innerHTML et 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.

### DOM XSS dans le puits InnerHTML en utilisant la source location.search

Vulnérabilité XSS DOM dans la fonctionnalité de recherche du blog. Le code récupère la valeur de `location.search` et l'insère directement dans le DOM via `innerHTML`, ce qui permet d'injecter et d'exécuter du JavaScript lorsque la valeur provient de l'URL.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b8aa13280eb3315c3528a9d2f7eb497be0dd6550%2F%7B444963A0-370C-4F85-93C2-2326197EB4F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Extrait du code observé**

```javascript
function doSearchQuery(query) {
    document.getElementById('searchMessage').innerHTML = query;
}
var query = (new URLSearchParams(window.location.search)).get('search');
if(query) {
    doSearchQuery(query);
}
```

**Charges utiles testées**

* Charge utile simple (non interprétée) : / `<script>alert("XSS")</script>`
* Test pour insérer un élément image : / `<img src="test"</img>`/ (cela ne déclenche pas l'exécution du script car aucun attribut d'événement n'est présent)

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9d9efd80509a8f8ce27bb73dd64d4adfb8d92fc2%2F%7B50C1DB2A-BBDD-44E0-928A-257F04334961%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7b594a4e05aaaf7c0f0ede7df51965c9e9a42931%2F%7B24AED474-87F4-494A-AF22-B2D9ACC0341F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Forcer une erreur de chargement pour déclencher un `onerror` gestionnaire : / `<img src=0 onerror=alert("XSS")>` / (Cette charge utile utilise l' `onerror` attribut d'événement pour exécuter `une alerte` lorsque le chargement de l'image échoue)

```javascript
<img src=0 onerror=alert("xss")>
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8c45da08fcdb3080fc6cb4f6629f73c9ec937ec0%2F%7B3A8EB142-F97F-4D96-9104-AFF814B2380C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Le script affecte directement `innerHTML` avec le `recherche` la valeur de l'URL ; par conséquent, des fragments HTML contenant des gestionnaires d'événements (par ex. `onerror`) ou des balises exécutables peuvent entraîner l'exécution de code. Le `<img src=0 onerror=alert("XSS")>` charge utile provoque une erreur de chargement et exécute `alert("XSS")`, démontrant la vulnérabilité XSS DOM.


---

# 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-with-innerhtml-and-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.
