RECONNAISSANCE
Detecting GraphQL APIs
GraphQL has many implementations written in a variety of programming languages, each of which could have different default configurations or known weaknesses
GraphQL Implementations and Languages
Apollo
TypeScript
Graphene
Python
Yoga
TypeScript
Ariadne
Python
graphql-ruby
Ruby
graphql-php
PHP
graphql-go
Go
graphql-java
Java
Sangria
Scala
Juniper
Rust
HyperGraphQL
Java
Strawberry
Python
Tartiflette
Python
Common Endpoints
Endpoints like
/graphql
or IDE endpoints (/graphiql
,/playground
) are common but can be customized.
Example Endpoint Definition in Graphene:
Graphene, a Python-based implementation of GraphQL, can expose two endpoints, one for GraphQL, and the other for GraphiQL Explorer, which is built into Graphene:
Common GraphQL Responses
If the operation is a query, the result of the operation is the result of executing the operation’s top-level selection set with the query root operation type. An initial value may be provided when executing a query operation: ExecuteQuery(query, schema, variableValues, initialValue)
Let
queryType
be the root Query type in the schema.Assert:
queryType
is an Object type.Let
selectionSet
be the top-level selection set in the query.Let data be the result of running
ExecuteSelectionSet(selectionSet, queryType, initialValue, variableValues)
normally (allowing parallelization).Let errors be any field errors produced while executing the selection set.
Return an unordered map containing data and errors. In practice, this means a GraphQL API will return a data JSON field when there is a result to return to a client’s query. It will also return an errors JSON field whenever errors occur during the execution of a client query.
GraphQL APIs follow a standardized response structure, making them relatively easy to identify during penetration tests or bug bounty hunts. According to the GraphQL specification:
Valid Query Response:
Returns a
data
JSON field containing the requested data.
Invalid Query Response:
Returns an
errors
JSON field with details about the issue.
These predictable behaviors allow automated tools to identify GraphQL APIs by sending test queries and observing responses.
Nmap Scan
A common GraphQL response returned when a client makes a GET request.
With this information, we now have the ability to automate a scan and pick up any other GraphQL servers that may exist on a network.
The __typename Field
Meta-fields are built-in fields that GraphQL APIs expose to clients. One example is __schema (part of introspection in GraphQL). Another example of a meta-field is __typename. When used, it returns the name of the object type being queried.
As you can see, GraphQL tells us that the pastes object’s type name is PasteObject. The real hack here is that the __typename meta-field can be used against the query root type as well
GraphQL tool based on Python for detecting GraphQL and performing implementation-level fingerprinting.
Graphw00f allows you to specify a custom list of endpoints when running a scan. If you don’t provide a list, Graphw00f will use its hardcoded list of common endpoints whenever it is tasked with detecting GraphQL.
Detecting GraphiQL Explorer and GraphQL Playground
Introspection
State of Introspection in GraphQL Implementations (Table 4-2)
Python
Graphene
Enabled
No
Python
Ariadne
Enabled
Yes
PHP
graphql-php
Enabled
Yes
Go
graphql-go
Enabled
No
Ruby
graphql-ruby
Enabled
Yes
Java
graphql-java
Enabled
No
An introspection query in its simplest form
Response:
Visualizing Introspection Data
Use GraphQL Voyager to explore schema relationships:
Navigate to GraphQL Voyager.
Paste the introspection response or upload the SDL file.
View relationships visually (e.g.,
PasteObject
links toOwnerObject
).
A GraphQL introspection detection with the Nmap NSE
Visualizing Introspection with GraphQL Voyager
Generating Introspection Documentation with SpectaQL
SpectaQL (https://github.com/anvilco/spectaql) is an open source project that allows you to generate static documentation based on an SDL file. The document that gets generated will include information about how to construct queries, mutations, and subscriptions; the different types; and their fields. We’ve hosted an example SpectaQL-generated schema of DVGA at http://lab.blackhatgraphql.com:9001 so you can see how SpectaQL looks when it’s functional.
Last updated
Was this helpful?