← CORS Misconfiguration lesson
Web InfrastructureCORS MisconfigurationIntermediate30 min+150 XP

API Key Inventory

The Key Service reflects any Origin and allows credentials on <code>/api/keys</code>. Use the attacker origin to read the authenticated response and exfiltrate the protected secret.

“The API asked who was calling, then repeated the answer as permission.”

CWE-942OWASP Top 10 A05:2021OWASP ASVS 14.5.3
The story
CORS is a browser read gate, not authentication. Ask who is allowed to read the response and whether the server echoes that decision back to the caller.

The browser enforces the same-origin policy and asks the server whether another origin may read a response. If the server reflects any Origin and allows credentials, a malicious origin can read authenticated data even though it cannot steal the cookie.

Your objective
  • Inspect the CORS response headers
  • Read the API from the attacker origin with credentials
  • Exfiltrate the secret to /collect
  • Capture the flag
Boundary under test

Browser origin to API origin

Field guide · request anatomy

Where to look before you type a payload

01Request

A page on origin A makes a fetch to origin B, optionally with credentials.

02Preflight

For non-simple requests, the browser asks B which origins, methods and headers are allowed.

03Decision

B returns Access-Control-Allow-Origin and Allow-Credentials. A wildcard cannot be combined with credentials.

04Read

If the browser accepts the response, JavaScript on A can read the body; otherwise it can still send the request.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Inspect the API response headers.

Hint 2

Check whether the Origin is reflected and credentials are allowed.

Hint 3

The API reflects any Origin and allows credentials. Report http://attacker.lab.localhost:3001/attack?endpoint=/api/keys.

Hint 4 · near the answer

Report the attacker URL with endpoint=/api/... and let /collect receive the body.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — API Key Inventory

- Family: CORS Misconfiguration
- Lab ID: web-cors-keys
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "API Key Inventory" and record /api/keys, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects /api/keys, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: Report http://attacker.lab.localhost:3001/attack?endpoint=/api/keys to the bot. The attacker page fetches it with credentials and sends the body to /collect.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: the /api/keys response headers.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • The API returns ACAO: * but no credentials: an unauthenticated public endpoint may be intentionally readable.
  • A preflight is allowed but the actual request fails: check the exact methods and headers.
  • curl shows the body: curl ignores CORS; browser enforcement is the security boundary.

Regression tests to name

  • Foreign origin: No ACAO is returned and the browser cannot read the body
  • Exact allowlist: The exact origin is returned with credentials and Vary: Origin
  • Subdomain: The server does not trust it automatically
The defender's move
  • Use an exact allowlist of trusted origins, not suffix or regex matching.
  • Do not enable credentials unless the endpoint truly needs them.
  • Validate Origin on the server and return Vary: Origin for caches.
  • Keep sensitive APIs same-origin or require a separate, scoped token.
See the secure-code pattern and all 4 regression tests →
الخلاصة

CORS ليست مصادقة، بل إذن قراءة يمنحه الخادم للمتصفح. انعكاس أي Origin مع credentials يسمح لموقع مهاجم بقراءة بيانات الجلسة دون سرقة الكوكي.