Skip to main content
2 min read Intermediate API

GraphQL Pentesting Guide.

Blogs

CreditsURL
PortSwiggerGraphQL Basics Level 1
GraphQL with labs
HacktricksPentesting Web - GraphQL
The Bilal RizwanGraphQL Common Vulnerabilities: How to Exploit Them
OWASPTesting GraphQL
CyberW1ngGraphQL API Vulnerabilities in Web App Penetration Testing 2023
Anugrah SRGraphQL Pentesting for Dummies Part 1
Escape TechPentest 101
Pentesting 102

Tool

CreditsURL
Dolev Farhigraphw00f
doyensecInQL
GraphQL KitGraphQL Voyager
GraphQL(https://github.com/graphql/graphiql)
GraphQLOnline GraphiQL

Videos

CreditsURL
Rahul Shetty AcademyYouTube Playlist
Insider PhDYouTube Video 1
Insider PhDYouTube Video 2
HowToGraphQLIntroduction

Vuln Lab

CreditsURL
DVGA (Dolev Farhi)Damn Vulnerable GraphQL Application
PortSwiggerPortSwigger
righettodPoC GraphQL
StackHawkVuln GraphQL API

Basics of GraphQL

Schema

The Schema defines the capabilities of the API and represents the contract between the client and the server. It defines the types available in the API and how they can be queried and mutated.

Types

GraphQL allows you to define your own types, including Scalar types (e.g., Int, String, Boolean) and Object types (e.g., User, Post). Types represent the shape of data that can be queried.

Schema

The Schema defines the capabilities of the API and represents the contract between the client and the server. It defines the types available in the API and how they can be queried and mutated.

Types

GraphQL allows you to define your own types, including Scalar types (e.g., Int, String, Boolean) and Object types (e.g., User, Post). Types represent the shape of data that can be queried.

type Example {
id: ID
name: String
age: Int
isActive: Boolean
}
type User {
id: ID
name: String
email: String
posts: [Post]
}

Queries

Queries are used by the client to request specific data from the server. A query in GraphQL mirrors the shape of the response it expects to receive.

query GetUser {
user(id: "123") {
id
name
email
}
}

Mutations

Mutations are used to modify data on the server. They allow clients to create, update, or delete data.

mutation CreateUser {
createUser(input: { name: "John", email: "john@example.com" }) {
id
name
email
}
}

Fields

Fields are the basic unit of data retrieval in GraphQL. They are used to request specific pieces of data about an object.

query GetUser {
user(id: "123") {
id
name
email
}
}

Resolvers

Resolvers are functions that determine how to fetch the data for a particular field. Each field in a GraphQL schema typically has a corresponding resolver function.

const resolvers = {
Query: {
user: (parent, args, context, info) => {
// Logic to fetch user data
}
}
};

Directives

Directives provide a way to modify the behavior of a GraphQL query or mutation. They can be used to conditionally include fields, apply transformations, or provide metadata.

query GetActiveUsers {
users {
id
name
email
isActive @include(if: true)
}
}

Subscriptions

Subscriptions allow clients to receive real-time updates from the server. They enable a client to subscribe to specific events and receive notifications when those events occur.

subscription NewPosts {
newPost {
id
title
content
}
}