GraphQL Injection

GraphQL is a query language for APIs and a runtime for fulfilling those queries with existing data. A GraphQL service is created by defining types and fields on those types, then providing functions for each field on each type

Summary

Tools

Enumeration

Common GraphQL Endpoints

Most of the time GraphQL is located at the /graphql or /graphiql endpoint. A more complete list is available at danielmiessler/SecLists/graphql.txtarrow-up-right.

Identify An Injection Point

Check if errors are visible.

Enumerate Database Schema via Introspection

URL encoded query to dump the database schema.

URL decoded query to dump the database schema.

Single line queries to dump the database schema without fragments.

Enumerate Database Schema via Suggestions

When you use an unknown keyword, the GraphQL backend will respond with a suggestion related to its schema.

You can also try to bruteforce known keywords, field and type names using wordlists such as Escape-Technologies/graphql-wordlistarrow-up-right when the schema of a GraphQL API is not accessible.

Enumerate Types Definition

Enumerate the definition of interesting types using the following GraphQL query, replacing "User" with the chosen type

List Path To Reach A Type

Methodology

Extract Data

HTB Help - GraphQL injection

Extract Data Using Edges/Nodes

Extract Data Using Projections

⚠️ Don’t forget to escape the " inside the options.

Mutations

Mutations work like function, you can use them to interact with the GraphQL.

GraphQL Batching Attacks

Common scenario:

  • Password Brute-force Amplification Scenario

  • Rate Limit bypass

  • 2FA bypassing

JSON List Based Batching

Query batching is a feature of GraphQL that allows multiple queries to be sent to the server in a single HTTP request. Instead of sending each query in a separate request, the client can send an array of queries in a single POST request to the GraphQL server. This reduces the number of HTTP requests and can improve the performance of the application.

Query batching works by defining an array of operations in the request body. Each operation can have its own query, variables, and operation name. The server processes each operation in the array and returns an array of responses, one for each query in the batch.

Query Name Based Batching

Send the same mutation several times using aliases

Injections

SQL and NoSQL Injections are still possible since GraphQL is just a layer between the client and the database.

NOSQL Injection

Use $regex inside a search parameter.

SQL Injection

Send a single quote ' inside a GraphQL parameter to trigger the SQL injection

Simple SQL injection inside a GraphQL field.

Labs

References

Last updated