Course contentsShow
← Security
Lesson 1007 of 3,05221. Web Security - API SecurityFree lesson

GraphQL Error Handling and Information Leakage

Preventing sensitive information disclosure through error messages, stack traces, and debugging data in GraphQL responses.

GraphQL Error Handling and Information Leakage

What you'll learn: How attackers exploit verbose GraphQL error messages to gain reconnaissance information about your API's internal structure and vulnerabilities.

The Information Disclosure Problem

GraphQL servers, especially in development mode, often return detailed error messages that reveal far too much about your application's internals. These verbose errors can include stack traces, database schema details, internal file paths, resolver logic, and debugging information that attackers use to map your system and craft targeted exploits.

Think of it like a burglar casing your house: every error message that says "User with ID 123 not found in users table" or reveals "/app/src/resolvers/payment.js:47" is like leaving your floor plans on the front porch.

Common Information Leaks

Stack Traces: Full call stacks expose your code structure, file paths, and dependency versions—all valuable reconnaissance data.

Database Errors: Raw SQL errors reveal table names, column structures, and database types, making SQL injection attempts easier.

Resolver Paths: Error messages showing which resolver failed expose your API's internal organization and business logic.

Validation Details: Overly specific validation errors ("creditCardNumber must be 16 digits") help attackers understand your data model and craft valid-looking payloads.

Secure Error Handling Strategy

Return generic error messages to clients: "An error occurred" or "Invalid input." Log detailed errors server-side only, where your team can access them securely. Implement different error handling for production versus development—verbose locally, minimal externally.

Disable GraphQL introspection in production. Use custom error formatters to sanitize all outbound error responses. Never expose internal implementation details, database specifics, or stack traces to API consumers.

Key Takeaway: Generic, sanitized error messages protect your GraphQL API from reconnaissance attacks, while detailed server-side logging preserves debugging capability—always treat error responses as potential intelligence leaks to adversaries.