Is your GraphQL API wide open? A 10-minute check for AI-built apps
If your AI-built app uses GraphQL, there is one question to ask first: can a stranger ask your API what it contains, and can they ask for everything at once? GraphQL gives clients a lot of freedom. That is the point of it, and it is also why a few default settings matter more than they do in a plain REST API. Who is at risk Any app with a /graphql endpoint, including apps that use Hasura, Apollo,…
When an AI-built app utilizes GraphQL, it's crucial to ask whether a stranger can access the API's contents and retrieve everything in a single request. This flexibility is inherent to GraphQL, which is why certain default settings can be more significant than in a traditional REST API.
Several apps, including those using Hasura, Apollo, Supabase's GraphQL layer, or Next.js API routes, are at risk. This is largely due to AI tools activating the default settings, making it easier to build demos.
A common issue arises when introspection is left open in production. This exposes the complete list of types, queries, and mutations, effectively giving anyone a map of your data. There's also a lack of authorization on resolvers, meaning the endpoint checks if you're signed in but not if the record belongs to you, leading to an IDOR problem similar to REST.
Additionally, there are no depth or size limits, allowing a query to request an entire data lineage, which can exhaust server resources. Batching is unbounded, meaning a single request can contain hundreds of queries, which can easily surpass a login limit of five attempts. Errors are verbose, displaying field names, stack traces, or SQL, which can compromise sensitive information.
To ensure your GraphQL API is secure, you can perform a 10-minute check. First, locate the endpoint, typically /graphql or /api/graphql. Then, send an introspection query using a tool like curl or your browser's developer tools. If you receive the full type list without signing in, introspection is open.
Next, sign in as a test user, copy a request that fetches their data, and modify the ID to that of another test user. If you can access the other user's data, authorization checks are missing. You can also test for depth limits by sending a query nested several levels deep. If the server still responds, there's no depth limit. For batching, send a request containing the same login mutation multiple times and check if the server processes each one. Lastly, observe the error messages. They should be short and generic.
If everything checks out, introspection should be disabled in production, and every resolver should verify ownership. A maximum query depth and complexity should be set, along with a timeout for requests. Batching should be limited or disabled for sensitive operations like logins, and errors returned to clients should be generic, while detailed logs should be kept on the server.
You can also use an AI builder to perform these checks. Simply provide the following prompt: "Review the GraphQL server. Disable introspection in production, add authorization checks for ownership in every resolver, set a maximum query depth and complexity, limit batched operations on login and password mutations, and return generic error messages to clients."
For a free scan, you can use ProofForge, which evaluates your GraphQL server from the outside, checking whether a stranger can see your data and whether they can access data belonging to another user. This scan is a one-time service, starting at $9.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to