> 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 和 location.search 在 href 属性中的 DOM XSS 笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、Burp Suite 验证和修复 c

### 使用 location.search 作为源的 JQuery 锚点 href 属性 sink 中的 DOM XSS

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ab4262062acd2338796992d1123d759e2b22617c%2F%7BDEA680DF-93BC-4DBC-8C56-DE289A554F15%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**观察：**

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

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

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

要获取会话 cookie 并显示：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fbefe0816b47e04b0c660b746beea1a405f8203b%2F%7B1F6159B5-826F-4C62-B7BD-553F80FC3367%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/zh/web/xss/dom-xss-in-href-attribute-with-jquery-location-search.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
