How to fix: GraphQL endpoint has no rate-limit headers
GraphQL POST endpoints need rate-limiting because one query can touch many resolvers.
Why it matters
A single GraphQL request can fan out to dozens of resolvers, consuming database connections and CPU far beyond what a per-request IP limit catches, letting attackers exhaust server resources with a small number of cheap HTTP calls.
GraphQL POST endpoints need rate-limiting because one query can touch many resolvers.
How to fix it
- 1Rate-limit by query cost and depth, not just request count
- 2Use graphql-rate-limit or a token-bucket middleware keyed on the authenticated user
- 3Return 429 with Retry-After when limits are exceeded
Code examples
graphql-rate-limit: per-user rate limit
import { createRateLimitDirective, defaultKeyGenerator } from 'graphql-rate-limit';
const rateLimitDirective = createRateLimitDirective({
keyGenerator: (directiveArgs, obj, args, context) =>
`${context.user?.id ?? context.ip}:${defaultKeyGenerator(directiveArgs, obj, args, context)}`,
});
// In SDL:
// type Query {
// searchUsers(q: String!): [User] @rateLimit(window: "1m", max: 20)
// }Express: global rate limit for GraphQL endpoint
import rateLimit from 'express-rate-limit';
const gqlLimiter = rateLimit({
windowMs: 60 * 1000,
max: 60,
message: { errors: [{ message: 'Too many requests' }] },
standardHeaders: true,
legacyHeaders: false,
});
app.use('/graphql', gqlLimiter);References
Detected automatically by VulnRadar. The check id is api-graphql-no-rate-limit, stable across every scan so you can filter or diff on it.
More api checks
- LowTRACE method referenced in API response body
- InfoREST endpoint allows DELETE
- LowGraphQL introspection field suggestions
- LowOpenAPI server URL leaks internal host
- LowCORS preflight result not cached
- HighBearer token in URL query string
- MediumJSONP callback parameter accepted
- InfoPUT method listed in Allow header
Questions
- How severe is GraphQL endpoint has no rate-limit headers?
- VulnRadar rates this medium severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id api-graphql-no-rate-limit, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does GraphQL endpoint has no rate-limit headers map to?
- It maps to CWE-799. In the OWASP Top 10 it falls under A04:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.