> 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/zh/web/xss/xss-in-template-literal-with-escaped-unicode.md).

# 在带有转义 Unicode 字符的字面模板中的 XSS

### 通过角括号、单引号、双引号、反斜杠和反引号的 Unicode 转义将反射型 XSS 注入模板字面量

在字面模板（反引号）中反射的 XSS，其中 `<` 和 `>` 角括号以及单引号和双引号都已编码，而反引号则以 Unicode 转义。目标：使 `alert()` 在字符串模板中执行。

search 参数被反射到一个 JavaScript 字面模板中。必须打破模板字符串才能运行 `alert()` 来自反射值的内容。

<pre class="language-javascript"><code class="lang-javascript">var message = `2 个搜索结果，搜索词为 'test'`;
<strong>document.getElementById('searchMessage').innerText = message;
</strong></code></pre>

<figure><img src="/files/8129004f8f4457ae9721ef1df56d0ba820997035" alt=""><figcaption></figcaption></figure>

* 反引号字符（`` ` ``）用于分隔模板字面量；页面会对用户提供的反引号进行转义（例如，使用 Unicode 转义），从而阻止简单的突破。

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

JS 插值差异示例（示意）：

```javascript
variable = "Testing";
console.log("变量是：${variable}")
console.log(`变量是：${variable}`)
```

<figure><img src="/files/6b32589e2724cdcedb5195594433de277c2e431e" alt=""><figcaption></figcaption></figure>

第一行会原样显示 `${variable}`，第二行则使用反引号解析变量。

* 尝试插入一个会运行的插值表达式 `alert()`:

```javascript
${alert(0)}
```

<figure><img src="/files/bc44e01b436e3cb6095dc0b838066b66d1ab49c7" alt="" width="520"><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/zh/web/xss/xss-in-template-literal-with-escaped-unicode.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.
