> 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/dom-xss-in-href-attribute-with-jquery-location-search.md).

# 带有 jQuery 和 location.search 的 href 属性中的 DOM XSS

### 在 JQuery 锚点 href 属性接收点中，使用 location.search 作为来源的 DOM XSS

反馈页面存在 DOM XSS 漏洞。该站点使用 `$` jQuery 的函数来选择一个 `<a>` 元素（返回链接）并将其 `href` 属性替换为从 `location.search`中提取的值。该值可通过 URL 控制。

**实验分析：**/ 使“返回”链接触发 `alert(document.cookie)` 当你点击它时（运行一个包含页面 cookies 的 alert）。

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

**观察：**

* “返回”按钮指向站点根目录；它连接到一个 `returnPath` URL 中的参数。
* 通过修改 `returnPath`，你可以定义 `href` 链接的目标。

在其中使用 JavaScript 协议 `href`:

```javascript
javascript:alert(0)
```

要获取会话 cookie 并显示：

```javascript
javascript:alert(document.cookie)
```

<figure><img src="/files/08391b77d20b4c9ade45f79a173e5c23751090fd" 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/dom-xss-in-href-attribute-with-jquery-location-search.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.
