OWASP WSTG v4.2 Explained

OWASP WSTG: Part 13 - API Testing (GraphQL)

WSTG v4.2 section 4.12 explained: testing GraphQL APIs, including introspection, authorization (BOLA/BFLA), injection, denial-of-service and batching attacks, with queries and fixes, plus how the broader API Security Top 10 fits.

9 min read
views
visits
OWASP WSTG Part 13 - API Testing
OWASP WSTG Part 13 - API Testing

APIs are now the core of most applications, and they move the attack surface from rendered pages to raw data operations. WSTG v4.2 added an API Testing category with one scenario, GraphQL, because it introduces attack surface that REST does not: a single endpoint, a self-describing schema, nested queries and request batching.

API Testing (WSTG section 4.12, ID WSTG-APIT-01) is this final part. Because one scenario does not cover everything API security needs, this part also maps how the rest of the series, and the OWASP API Security Top 10, apply to APIs in general.

Source: WSTG v4.2 §4.12 API Testing (CC BY-SA 4.0), explained and expanded. Only test systems you are authorised to test.


Key Takeaways

  • Introspection hands over the whole schema: if enabled in production, the attacker gets your full API map for free.
  • Authorization is the #1 API risk: object-level (BOLA/IDOR) and function-level (BFLA) checks must be on every field and resolver.
  • GraphQL changes DoS and injection: nested queries and batching let one request do enormous or repeated work.
  • The injection, auth and input tests from earlier parts still apply, just carried over JSON/GraphQL instead of forms.
  • Fix with schema discipline: disable introspection in prod, depth/complexity/rate limits, per-field authorization, input validation.

GraphQL’s Extra Attack Surface

flowchart TD
    EP["Single endpoint /graphql"] --> INTRO["Introspection<br/>full schema disclosure"]
    EP --> AUTHZ["Authorization per field/resolver<br/>BOLA / BFLA"]
    EP --> INJ["Injection via arguments<br/>SQLi, NoSQLi, XSS in returned data"]
    EP --> DOS["Deeply nested / aliased queries<br/>resource exhaustion"]
    EP --> BATCH["Batching / aliases<br/>brute force, rate-limit bypass"]

WSTG-APIT-01: Testing GraphQL

1. Introspection (schema disclosure)

What it checks: whether the API answers introspection queries, which return the entire schema: every type, field, query and mutation.

How to test:

1
2
3
query IntrospectionQuery {
  __schema { types { name fields { name } } queryType { name } mutationType { name } }
}

If this returns the schema, explore it visually with GraphiQL, GraphQL Playground, GraphQL Voyager, or Burp’s InQL. Introspection is invaluable for development but should be off in production: it reveals hidden mutations (admin operations, debug fields) you would otherwise have to guess.

Fix: disable introspection in production; also disable the GraphiQL/Playground UIs; consider field suggestions off (they leak field names even with introspection disabled).

2. Authorization (BOLA / BFLA)

What it checks: that every query and mutation enforces authorization, for the specific object and the specific function. This is the top risk in APIs.

  • BOLA (object level, = IDOR): user(id: 123) returns another user’s data because the resolver does not check ownership. Test by requesting objects you should not own (ties to Part 6, ATHZ-04).
  • BFLA (function level): a normal user calls an admin-only mutation (deleteUser, promoteUser) that the schema exposed via introspection. Test by invoking privileged operations with a low-privileged token.
1
mutation { deleteUser(id: "2") { success } }   # as a normal user -> should fail

Fix: enforce authorization in every resolver, for both the object and the operation; do not rely on the client not knowing a field exists.

3. Injection

What it checks: that GraphQL arguments reaching a database, OS command or the browser are handled safely. GraphQL does not sanitise input; a resolver that builds a SQL/NoSQL query from an argument is injectable just like a REST endpoint.

How to test: put the injection probes from Part 8 into GraphQL arguments (SQLi, NoSQLi), and test returned data rendered in a browser for XSS. sqlmap can target a GraphQL request captured to a file.

Fix: parameterised queries, input validation (e.g. graphql-constraint-directive), and output encoding, same as everywhere else.

4. Denial of Service via queries

What it checks: whether a single query can force disproportionate work. GraphQL’s nesting makes this easy: circular relationships can be requested to great depth, and aliases multiply work.

1
2
# Deeply nested: each level multiplies the work
{ a { b { a { b { a { b { ... } } } } } } }

How to test: send deeply nested and heavily aliased queries (within authorised, careful limits) and observe resource use and response time.

Fix: enforce query depth and complexity/cost limits, set timeouts, paginate list fields, and rate-limit.

5. Batching attacks

What it checks: GraphQL’s ability to send many operations in one request (query batching or aliases), which bypasses per-request rate limits, this is how attackers brute-force OTPs/passwords or enumerate at speed through a single HTTP call.

1
2
# One request, many login attempts via aliases -> defeats per-request throttling
{ a: login(user:"x", pass:"1"){ok} b: login(user:"x", pass:"2"){ok} c: login(...){ok} }

How to test: alias the same sensitive operation many times in one request and see whether rate limiting counts operations or only HTTP requests.

Fix: limit or disable batching on sensitive operations, rate-limit by operation (not just by request), and cap the number of aliases/operations per request.


Beyond GraphQL: Testing Any API

WSTG v4.2 only ships the GraphQL scenario, but REST, gRPC and SOAP APIs are tested with the same categories from this series plus the OWASP API Security Top 10 (2023):

API Top 10 (2023) Where this series covers it
API1 Broken Object Level Authorization (BOLA) Part 6, ATHZ-04 (IDOR)
API2 Broken Authentication Part 5
API3 Broken Object Property Level Authorization Mass assignment / excessive data (Part 4, Part 6)
API4 Unrestricted Resource Consumption Rate limiting, DoS queries (this part, Part 5 ATHN-03)
API5 Broken Function Level Authorization (BFLA) Part 6, ATHZ-02/03
API6 Unrestricted Access to Business Flows Part 11 Business Logic
API7 Server-Side Request Forgery Part 8, INPV-19
API8 Security Misconfiguration Part 3
API9 Improper Inventory Management Shadow/old API versions (Part 2)
API10 Unsafe Consumption of APIs Trusting third-party APIs (Part 8 input validation)

Practical REST/API testing steps: get the spec (OpenAPI/Swagger) or reconstruct it by proxying the app and mobile client; import it into Burp/Postman; test every endpoint for the Top 10, especially object- and function-level authorization with two accounts; and look for shadow endpoints (old versions, undocumented routes) that skipped the current controls.


Worked Example: Introspection + Batching → Admin Takeover

1. Introspection hands over the schema, including a mutation the UI never shows:

1
2
3
curl -s https://api.example.com/graphql -H 'Content-Type: application/json' \
  -d '{"query":"{ __schema { mutationType { fields { name } } } }"}' | jq
# ... "promoteToAdmin" ...   <- a privileged mutation, discovered for free

2. BFLA — call that privileged mutation with a normal user’s token (no field-level authorization):

1
mutation { promoteToAdmin(userId: "me") { id role } }
1
{ "data": { "promoteToAdmin": { "id": "1337", "role": "ADMIN" } } }

3. Batching defeats rate limiting on sensitive operations, aliases run many logins in one HTTP request, so a per-request throttle never fires:

1
2
3
4
5
6
{
  a: login(user:"admin", pass:"Spring2024!") { token }
  b: login(user:"admin", pass:"Summer2024!") { token }
  c: login(user:"admin", pass:"Autumn2024!") { token }
  # ...hundreds more aliases in a single request
}

Fixed — three independent controls, each of which would have stopped the chain:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const server = new ApolloServer({
  schema,
  introspection: process.env.NODE_ENV !== 'production',   // 1. off in prod
  validationRules: [depthLimit(7), createComplexityLimitRule(1000)],  // 2. DoS limits
  plugins: [noBatchedMutations()],   // 3. disallow batching on sensitive ops
});

// every resolver enforces object- AND function-level authorization
const resolvers = {
  Mutation: {
    promoteToAdmin: (parent, args, ctx) => {
      if (!ctx.user?.isAdmin) throw new ForbiddenError('not allowed');  // the real fix
      return users.promote(args.userId);
    },
  },
};

Why GraphQL needs its own attention. One endpoint, a self-describing schema and request batching mean the usual perimeter assumptions (per-URL rate limits, “hidden” admin routes) quietly stop holding. The underlying bugs are still the familiar ones, BOLA/BFLA from Part 6 and injection from Part 8, but GraphQL hands the attacker a map and a megaphone.


Hands-on Practice

  • PortSwigger Academy — the GraphQL API vulnerabilities labs cover introspection, suggestions, BOLA and brute-force via aliases.
  • Damn Vulnerable GraphQL Application (DVGA) — a deliberately vulnerable GraphQL target for every test here.
  • Burp InQL / GraphQL Voyager — explore and attack a schema interactively.
  • For REST APIs, import an OpenAPI/Swagger spec into Postman or Burp and drive the API Security Top 10 against two accounts.

Checklist: API Testing

Area Test Key tools
GraphQL introspection Schema disclosure in production InQL, GraphiQL, Voyager
GraphQL authorization BOLA / BFLA per field and resolver Burp, two accounts
GraphQL injection SQLi/NoSQLi/XSS via arguments sqlmap, Burp
GraphQL DoS Nested/aliased query limits Burp, manual queries
GraphQL batching Rate-limit bypass via aliases Burp, InQL
REST/other APIs API Security Top 10, shadow endpoints Burp, Postman, OpenAPI spec

The Series, End to End

That completes the OWASP Web Security Testing Guide v4.2: 13 parts, 12 categories, ~100 tests. Used together they form a repeatable methodology:

  1. Understand the target (Part 2) and its deployment (Part 3).
  2. Attack identity and access: who exists (Part 4), authentication (Part 5), authorization (Part 6), sessions (Part 7).
  3. Attack the data path: input validation (Part 8), errors (Part 9), crypto (Part 10).
  4. Attack the intent: business logic (Part 11), the client (Part 12), and APIs (this part).

Then report findings with their WSTG IDs and fixes, as covered in Part 1.

Previous: Part 12 - Client-side Testing · Start over: Part 1 - Introduction & Methodology


References

Further reading & labs

Comments

Questions, corrections or another approach? Comment with your GitHub account.

Open Research & Community Labs
صدقة جارية • Ongoing Charity

Empowering the Cybersecurity Community

All research, lab walkthroughs, and technical series on this platform remain 100% free. You can support server hosting, research environments, and lab infrastructure.

Support & Wall of Honor
اللهم اجعل هذا العمل علمًا نافعًا وصدقةً جارية، واكتب لي به الأجر والقبول، وانفع به كل من قرأه أو تعلّمه.
اللهم احفظ لي والديّ وأهلي، وبارك في أعمارهم وصحتهم، وأدم عليهم نعمة الصحة والعافية، ولا تريني فيهم بأسًا يبكيني.
Dedicated as ongoing charity and beneficial knowledge. May Allah bless my parents and family, protect them, and grant them lasting health and happiness.