Day 8 of 2160 minShell WalkerHands-on lab

Day 8: APIs, CORS and GraphQL: A Review Hunt

Taught by Mr Elite Updated

By the end of today you can

  • Explain why reflected Origin plus credentials lets another site read private data
  • Test CORS behaviour with curl and read the response headers correctly
  • Use GraphQL introspection to list queries and find fields the docs never mention
  • Start a bug class table that links each flaw to one concrete test

Warm-up

Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.

What is the difference between IDOR and mass assignment?

IDOR changes an identifier to reach someone else's object. Mass assignment sets fields the form never offered.

Why did we use Repeater and a baseline when testing access control?

Changing one thing and comparing against the original response shows exactly what that change caused.

Picture an API that returns your account balance as JSON. It checks your session cookie, so only you can read it. Then a developer adds a quick fix so a front end on another domain can call it, and the fix copies whatever origin asks into the response headers. Now any website you visit can quietly read your balance using your own logged-in browser.

Today is a review day, so we pull earlier habits together: read the traffic, change one thing, compare, prove it. We apply them to two API flaws, CORS origin reflection and GraphQL introspection. You will do both on practice labs, and everything hands-on runs on your own machine or the SecurityElites labs.

Why APIs need their own pass

An API is a web app with the interface removed. There is no page to click through, so the bugs live in headers, identifiers and request bodies. That suits you, because you already know how to read those from Days 5 to 7.

You can usually spot API traffic in your proxy history. The paths contain /api/ or /graphql, the request body is JSON, and the response is data rather than a page. When you see that, switch your attention from what the page looks like to what the headers and fields say.

Browsers stop one site from reading another site's responses. This is the same-origin policy. CORS is the mechanism a server uses to relax that rule on purpose. The server lists who may read its responses in a header, and the browser obeys.

Origin
The scheme, host and port of the page making the request, for example https://shop.example.
Access-Control-Allow-Origin (ACAO)
A response header naming the origin allowed to read the response.
Access-Control-Allow-Credentials (ACAC)
When true, the browser lets that origin read responses to requests that carried cookies.
Origin reflection
The server copies the incoming Origin header straight into ACAO without checking it against a list.

Reflection alone is mostly harmless for public data. Reflection plus credentials true is the dangerous pair, because the attacker's page can then read data that only a logged-in user should see.

Here is the attack story in plain steps, so you know what you are really proving. A victim is logged in to the bank in one tab. They open a hostile page in another tab. That page asks the bank API for the balance, the browser attaches the bank cookie, and the weak CORS headers tell the browser the hostile page may read the answer. The server never sees anything unusual, which is why this bug survives so long.

Quick check

A response has Access-Control-Allow-Origin: * and no credentials header. Which statement is most accurate?

Watch me do it: CORS on your own machine

Before the lab, I want you to see the flaw in a server you built yourself. We make a tiny deliberately weak API on localhost, then test it with curl. Nothing leaves your computer, and nobody else can reach it, because it listens on 127.0.0.1 only.

python
from http.server import BaseHTTPRequestHandler, HTTPServer
import json

class H(BaseHTTPRequestHandler):
    def do_GET(self):
        origin = self.headers.get("Origin")
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        if origin:
            self.send_header("Access-Control-Allow-Origin", origin)
            self.send_header("Access-Control-Allow-Credentials", "true")
        self.end_headers()
        self.wfile.write(json.dumps({"user": "alice", "balance": 1200}).encode())
    def log_message(self, *a):
        pass

HTTPServer(("127.0.0.1", 8000), H).serve_forever()
A toy API that copies any Origin into ACAO and always allows credentials. Never deploy anything like this.
bash
curl -i -H "Origin: https://evil.example" http://127.0.0.1:8000/
curl -i -H "Origin: https://other.example" http://127.0.0.1:8000/
curl -i http://127.0.0.1:8000/
-i prints the response headers. Compare the CORS headers across all three runs.
text
HTTP/1.0 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: https://evil.example
Access-Control-Allow-Credentials: true

{"user": "alice", "balance": 1200}
Expected output of the first command, trimmed. A Server and Date line will also appear, and that is fine. The second run shows other.example instead, and the third shows no CORS lines at all.

Read what just happened. You never logged in, yet the server agreed that two different invented sites could read its answer. A safe server would compare the origin against a short allow list and stay silent for anything else. Keep this picture in mind, because the lab hides the same behaviour behind a login.

Quick check

In your third curl run, with no Origin header, the CORS headers were missing. What does that tell you?

GraphQL and introspection

GraphQL is an API style where the client sends one query to a single endpoint, usually /graphql, and asks for exactly the fields it wants. Because the shape of the data is described by a schema, GraphQL can describe itself. That feature is called introspection.

Introspection is helpful in development. In production it hands an attacker a map of every query, including ones the front end never uses, such as admin helpers left behind. Our job is to ask for the map, read it, and then check whether those hidden fields enforce any access control.

bash
curl -s -X POST "$LAB_URL/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query":"{ __schema { queryType { fields { name } } } }"}' | jq .
Asks the schema for the names of all top-level queries. jq makes the JSON readable.
bash
curl -s -X POST "$LAB_URL/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query":"{ __schema { queryType { fields { name type { name } } } } }"}' | jq .
Adds the return type of each field, so you can see which queries hand back users, notes or other objects.

An assistant can help you write follow-up queries, but you paste the real schema in and you run every query yourself. A guessed field name proves nothing, whereas a name you read from the live schema is solid evidence.

The labs

Two labs today, both on the SecurityElites platform, so you are safe to test freely. The first is cors-misconfig-1, where a bank API reflects the Origin and allows credentials. The second is graphql-introspection-1, where one /graphql endpoint hides an undocumented field. Open each from your lab panel and start with the one that feels less familiar.

Review: one table for every bug class

A hunter with a method beats one with a long list of tricks. For each bug class, I want you to hold three things: what it is, one test that shows it, and what proof looks like. We start the table with what you have done and add rows for classes coming up in the second half of the course.

Reflected XSS
Test: put a unique marker in a parameter and see where it lands in the page. Proof: script runs in your lab browser.
IDOR
Test: change an identifier to another user's. Proof: you read or change an object you do not own.
Mass assignment
Test: add an extra field such as role to a request. Proof: the server accepts it and state changes.
CORS reflection
Test: send a hostile Origin and read ACAO and ACAC. Proof: your origin is echoed with credentials true.
GraphQL introspection
Test: query __schema. Proof: hidden fields listed, then called without authorisation.
SSRF, OAuth, injection, races
Not tested yet. Add a one-line idea now and mark it untested. We fill these in properly from Day 16 onwards.

Notice the pattern in every row. The test is one small change, and the proof is something you can show to another person, not a feeling that the app looks odd. When a new bug class appears later, force yourself to fill in those same three cells before you start poking at it.

Quick check

Which row of your table gives the strongest proof of a CORS flaw?

Your turn

CORS Misconfiguration

This lab is a bank API whose CORS handler reflects the Origin header and allows credentials. It is the same flaw you just built locally, now behind a realistic authenticated endpoint. After it, take on graphql-introspection-1 from the lab panel to practise the second half of today.

Open the lab in a new tab

What to try

What to notice

  • Which header combination makes the reflection dangerous rather than merely untidy
  • Whether the server changes behaviour for origins that look similar to a trusted one
  • Which GraphQL field names the normal app never uses
  • Whether the hidden field asks for any authorisation at all

If it did not work

Testing CORS without sending an Origin header, then concluding the API is safe.

Always add an Origin header with curl. Many servers only emit CORS headers when they see one.

Reporting reflected Origin on its own as a high severity bug.

Check for Access-Control-Allow-Credentials: true and for sensitive authenticated data. Without both, the impact is small.

Trusting an assistant's guess at GraphQL field names instead of reading the real schema.

Run the introspection query, paste the real output, and let the assistant explain it. Your own request proves the field exists.

Forgetting to save the exact request that worked.

Copy the full curl command into notes straight after each success, with the key lines of the response.

Calling a hidden GraphQL field a vulnerability just because it appears in the schema.

Call the field without credentials. Only data returned without proper authorisation is a finding.

Recap

  • CORS lets a server choose which origins may read its responses, and the browser enforces that choice
  • Reflected Origin combined with credentials true lets another site read authenticated data
  • Always test CORS with a hostile Origin header, and compare against a request without one
  • GraphQL introspection maps every query, including hidden ones the app never calls
  • A hidden field is only a finding if it lacks proper authorisation
  • A bug class table of test plus proof keeps your method repeatable

Cheat sheet

curl -i -H "Origin: https://evil.example" URL
Send a hostile origin and show response headers
Access-Control-Allow-Origin
Which origin may read the response
Access-Control-Allow-Credentials: true
Cookies are allowed with the cross-origin read
{ __schema { queryType { fields { name } } } }
List top-level GraphQL queries
jq .
Pretty-print JSON in the terminal
Baseline, change one thing, compare
The core test loop for every bug class

Before the next day

Mission: Two labs and one table

Finish both labs and build the bug class table you will reuse for the rest of the course. This turns today's two flaws and earlier ones into a single reference you can search quickly.

About 40 min

You are done when: A folder with notes for both labs (exact commands plus harm sentences) and bug-class-table.md with at least five completed rows and four marked untested.

Want more? Edit weak_api.py so it only reflects origins from an allow list, rerun your curl tests, and confirm the hostile origin no longer gets ACAO.

Quiz

4 questions. Your score is saved with your progress.

1. Why is Access-Control-Allow-Credentials: true combined with a reflected Origin more serious than a reflected Origin alone?

2. You test an API with curl and see no CORS headers at all. What should you do next?

3. GraphQL introspection is enabled. Which finding actually needs more proof before you call it a vulnerability?

4. What is the best way to use an assistant during these labs?

Finish the day

Mark the day complete to save your progress.

Go to Day 9

Next: Day 9 turns to AI features themselves. You will practise prompt injection and system prompt leaks against lab chatbots, using the same baseline and compare habit you used today.

Tell someone you are doing this:WhatsAppXLinkedIn

Your notes

Private to this device. Write what you want to remember from today.