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

# 在 JavaScript 字符串中的反射型 XSS，HTML 编码的尖括号

### 带尖括号经 HTML 编码的 JavaScript 字符串中的反射型 XSS

本实验包含一个 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/111edcd738ddebdedd95f8fc77b4e40f695bc12d" alt=""><figcaption></figcaption></figure>

搜索值（`searchTerms`) 在一个 `document.write` 指令中，与由 JavaScript 构建的 HTML 字符串进行拼接。通过注入一个撇号（`'`) 到该值中，您可以关闭当前 JavaScript 字符串并执行任意代码。

```javascript
hello'
```

<figure><img src="/files/54d99e880c1bc6d99afa8deb5a28373b489f6ea4" alt=""><figcaption></figcaption></figure>

通过将以下字符串作为搜索值发送，您可以关闭字符串，运行 `alert(0)` 然后闭合：

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

<figure><img src="/files/9b950179d06337ccab03ca1bec845d7c986e2a29" 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/zh/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.
