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

# XSS mit CSP und Umgehungstechnik

### Reflektiertes XSS, geschützt durch CSP, mit CSP-Bypass

#### Lab-Beschreibung

Reflektiertes Cross-Site-Scripting, geschützt durch eine Content Security Policy (CSP). Das Ziel ist, auszuführen `alert()` durch Umgehung der CSP. Die vorgesehene Lösung funktioniert nur in Chrome.

#### Ziel

Finde einen durchdachten XSS-Vektor, der die CSP umgeht und die `alert()` Funktion aufruft.

Beobachtungen

* Durch das Injizieren eines `<script>` Tags in den Parameter erscheint der Tag im HTML, aber JavaScript wird nicht ausgeführt:/ Beispiel-Injektion: `'</h1><script>alert(0)</script>` — der Tag ist sichtbar, wird aber von der CSP blockiert.

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

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

CSP erlaubt nur Skripte von derselben Domain (`'self'`).

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

* Der CSP-Report zeigt an, dass ein Token erwartet wird (der `Token` Parameter scheint mit dem Verhalten der CSP zusammenzuhängen).

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

* Durch Hinzufügen von `&token=test` zur URL wird dieser Parameter von der Anwendung interpretiert.

```
&token=test
```

<figure><img src="/files/9251732893286f2af7b1abb526d4c29b76b9ef03" alt=""><figcaption></figcaption></figure>

Es ist möglich, direkt über den `Token` Parameter eine CSP-Direktive einzuschleusen, zum Beispiel:

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

die Direktive wird berücksichtigt

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

Nach dem erzwungenen Hinzufügen von `script-src-elem 'unsafe-inline'`, ermöglicht die folgende Injektion die Ausführung von JavaScript:

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

<figure><img src="/files/40107f55f6e1b0adc042886fa5a37b1b012f7a07" 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/de/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.
