> 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/xss-with-csp-bypass.md).

# XSS con CSP y técnica de evasión

### XSS reflejado protegido por CSP, con evasión de CSP

#### Descripción del laboratorio

Cross-site scripting reflejado protegido por una Política de Seguridad de Contenido (CSP). El objetivo es ejecutar `alert()` eludiendo la CSP. La solución prevista solo funciona en Chrome.

#### Objetivo

Encuentra un vector de XSS ingenioso que eluda la CSP y llame a la `alert()` función.

Observaciones

* Al inyectar una `<script>` etiqueta en el parámetro, la etiqueta aparece en HTML, pero JavaScript no se ejecuta. Ejemplo inyectado: `'</h1><script>alert(0)</script>` — la etiqueta es visible, pero la CSP la bloquea.

```javascript
' </h1><script>alert(0)</script>
```

<figure><img src="/files/31d28a07a14e32579d5e8820838b1a691e74d37e" alt=""><figcaption></figcaption></figure>

La CSP solo permite scripts del mismo dominio (`'self'`).

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

* El informe de la CSP indica que se espera un token (el `token` parámetro parece relacionado con el comportamiento de la CSP).

<figure><img src="/files/504249dcadca32b0c1f96877d2563e29e6e177b4" alt=""><figcaption></figcaption></figure>

* Al añadir `&token=test` a la URL, este parámetro es interpretado por la aplicación.

```
&token=test
```

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

Es posible inyectar una directiva de CSP directamente a través del `token` parámetro, por ejemplo:

```
&token=;script-src-elem 'unsafe-inline'
```

la directiva se tiene en cuenta

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

Después de forzar la adición de `script-src-elem 'unsafe-inline'`, la siguiente inyección permite la ejecución de JavaScript:

```javascript
<script>alert(0)</script>&token=;script-src-elem 'unsafe-inline'
```

<figure><img src="/files/d51dbdff6afc843fb0ec9a53a287fb8181c14338" 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/xss-with-csp-bypass.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.
