Sc graphql

From ersinkoc/security-check · View interactive version

Sc graphql is an AI agent skill from the GitHub repository ersinkoc/security-check. GraphQL injection, introspection abuse, query complexity attacks, and authorization bypass detection

How to use this skill

Skill file

SC: GraphQL Security

Purpose

Detects GraphQL-specific security vulnerabilities including query injection, introspection information disclosure, batching abuse, nested query denial-of-service, field-level authorization bypass, and subscription hijacking. Covers Apollo Server, graphql-yoga, Strawberry, Graphene, gqlgen, and HotChocolate.

Activation

Called by sc-orchestrator during Phase 2 when GraphQL schema files, resolvers, or GraphQL dependencies are detected.

Phase 1: Discovery

File Patterns to Search

**/*.graphql, **/*.gql, **/schema.*, **/typeDefs.*, **/resolvers.*,
**/*resolver*, **/*schema*, **/*graphql*, **/mutations/*, **/queries/*,
**/subscriptions/*, **/directives/*

Keyword Patterns to Search

"typeDefs", "resolvers", "ApolloServer", "graphql-yoga", "makeExecutableSchema",
"buildSchema", "@Query", "@Mutation", "@Resolver", "GraphQLObjectType",
"introspection", "depthLimit", "costAnalysis", "complexityLimit",
"__schema", "__type", "subscription", "directive"

Security Checks

1. Introspection Enabled in Production

2. Query Depth/Complexity Limits Missing

3. Batching Without Limits

4. Field-Level Authorization

5. SQL/NoSQL Injection in Resolvers

6. Information Disclosure via Error Messages

7. Subscription Authorization

Phase 2: Verification

Nested Query DoS Example

# Attack: Deeply nested query (no depth limit)
query {
  user(id: 1) {
    posts {
      author {
        posts {
          author {
            posts { # ...repeating to depth 50+
              title
            }
          }
        }
      }
    }
  }
}
// VULNERABLE: No depth or complexity limits
const server = new ApolloServer({
  typeDefs,
  resolvers,
});

// SAFE: With depth and complexity limits
import depthLimit from 'graphql-depth-limit';
import { createComplexityLimitRule } from 'graphql-validation-complexity';

const server = new ApolloServer({
  typeDefs,
  resolvers,
  validationRules: [
    depthLimit(10),
    createComplexityLimitRule(1000),
  ],
  introspection: process.env.NODE_ENV !== 'production',
});

Authorization Bypass Example

// VULNERABLE: No auth check in resolver
const resolvers = {
  Mutation: {
    deleteUser: async (_, { id }, context) => {
      return await User.findByIdAndDelete(id); // Anyone can delete any user
    }
  }
};

// SAFE: Auth check in resolver
const resolvers = {
  Mutation: {
    deleteUser: async (_, { id }, context) => {
      if (!context.user || context.user.role !== 'admin') {
        throw new ForbiddenError('Not authorized');
      }
      return await User.findByIdAndDelete(id);
    }
  }
};

Severity Classification

Output Format

Finding: GQL-{NNN}

Common False Positives

  1. Introspection in development — introspection is expected in dev/staging environments
  2. Public queries without auth — some queries are intentionally public (e.g., product listings)
  3. Depth limits in gateway — depth limiting may be enforced at the API gateway level, not in the GraphQL server
  4. Schema-first codegen — generated resolvers may appear to lack auth but are wrapped by middleware
  5. Federated schemas — auth may be handled by the gateway in a federated GraphQL architecture
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.