> 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-in-a-javascript-string-with-apostrophe-and-backslash-escaped.md).

# XSS в строке JavaScript с экранированными апострофом и обратной косой чертой

### Отражённый XSS в строке JavaScript с экранированной одинарной кавычкой и обратным слэшем

Отражённый XSS в функции отслеживания поисковых запросов. Отражаемое значение вставляется в строку JavaScript; простые апострофы и обратные слэши экранируются, что затрудняет выход из строки.

Цель

* Выйти из экранированной строки JavaScript и вызвать `alert()`.

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

Текущие наблюдения

* Если `тестирование` отправляется, значение сохраняется в `searchTerm` переменной скрипта.
* Попытка ввести новую переменную:/ `тестирование'; var=test='thisIsATest`/ → Замечено, что кавычки и обратные слэши () внедряются/присутствуют и не позволяют выполнить прямую инъекцию.

```bash
тестирование'; var=test='thisIsATest
```

* Просто вставка закрывающего тега скрипта может закрыть контекст скрипта: `</script>`

```javascript
</script>
```

<figure><img src="/files/979cab266bc031003d50ba18f2ea9dc6a140c2f3" alt=""><figcaption></figcaption></figure>

* После закрытия может быть отображён простой HTML-текст: `</script><h1>HACK</h1>`

```javascript
</script><h1>HACK</h1>
```

<figure><img src="/files/52cdebbd5c5f0d95ba49d0e17fa1e635ebd0b7dd" alt=""><figcaption></figcaption></figure>

* И наконец, можно выполнить `alert` добавив новый `<script>` после закрытия: `</script><script>alert(0)</script>`

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

<figure><img src="/files/9efeb616a949d274a79e8f5fe4f603b70563013c" 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/xss-in-a-javascript-string-with-apostrophe-and-backslash-escaped.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.
