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

# XSS avec CSP et technique de contournement

### XSS réfléchi protégé par CSP, avec contournement de CSP

#### Description du laboratoire

Script intersites réfléchi protégé par une Content Security Policy (CSP). L'objectif est d'exécuter `alert()` en contournant la CSP. La solution prévue ne fonctionne que sur Chrome.

#### Objectif

Trouvez un vecteur XSS ingénieux qui contourne la CSP et appelle la `alert()` fonction.

Observations

* En injectant une `<script>` balise dans le paramètre, la balise apparaît en HTML mais le JavaScript ne s'exécute pas :/ Exemple injecté : `'</h1><script>alert(0)</script>` — la balise est visible mais bloquée par la CSP.

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

<figure><img src="/files/3b5ed9cbc9db05ae6ad489e703996efe8990d499" alt=""><figcaption></figcaption></figure>

La CSP n'autorise que les scripts provenant du même domaine (`'self'`).

<figure><img src="/files/106227067224ebcd45c3281e059c8da61ec10837" alt=""><figcaption></figcaption></figure>

* Le rapport CSP indique qu'un jeton est attendu (le `jeton` paramètre semble lié au comportement de la CSP).

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

* En ajoutant `&token=test` à l'URL, ce paramètre est interprété par l'application.

```
&token=test
```

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

Il est possible d'injecter directement une directive CSP via le `jeton` paramètre, par exemple :

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

la directive est prise en compte

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

Après avoir forcé l'ajout de `script-src-elem 'unsafe-inline'`, l'injection suivante permet l'exécution de JavaScript :

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

<figure><img src="/files/f4601328e93339edadc5e82d8adc10851b1a2804" 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/fr/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.
