Skip to content

Commit b0554c0

Browse files
[API Shield/WAF] GraphQL rate limiting updates (#23766)
* graphql rate limiting updates * Apply suggestion from @pedrosousa Co-authored-by: Pedro Sousa <[email protected]> --------- Co-authored-by: Pedro Sousa <[email protected]>
1 parent d8f406c commit b0554c0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/content/docs/waf/rate-limiting-rules/best-practices.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,15 @@ _This example rule requires Advanced Rate Limiting._
341341

342342
## Protecting GraphQL APIs
343343

344-
One of the biggest challenges posed by applications built on GraphQL is that a single path manages all queries to the server, and every request is usually a `POST` operation.
344+
Preventing server overload for GraphQL APIs can be different from preventing overload for RESTful APIs. One of the biggest challenges posed by applications built on GraphQL is that a single path manages all queries to the server, and every request is usually a `POST` operation. This prevents different rate limits for different API use cases based on the HTTP method and URI path.
345345

346-
The purpose of the request is usually embedded in the body, which has information on what data the client wants to fetch or mutate (according to [GraphQL's terminology](https://graphql.org/learn/queries/) for server-side data modification), along with any additional data required to carry out the action.
346+
However, instead of using the method and path like a RESTful API, the purpose of the request is usually embedded in the body, which has information on what data the client wants to fetch or mutate (according to [GraphQL's terminology](https://graphql.org/learn/queries/) for server-side data modification), along with any additional data required to carry out the action.
347+
348+
To prevent server overload, consider the following approaches:
349+
350+
1. Limit the number of times a particular user can call the same GraphQL operation name.
351+
2. Limit the total amount of query complexity any given user is allowed to request.
352+
3. Limit any individual request's query complexity.
347353

348354
The following examples are based on an application that accepts reviews for movies. A GraphQL request could look like the following:
349355

@@ -376,7 +382,7 @@ To limit the rate of actions, you could use the following rule:
376382

377383
_This example rule requires Advanced Rate Limiting and payload inspection._
378384

379-
### Prevent server overload
385+
### Limit the total amount of query complexity
380386

381387
The complexity necessary to handle a GraphQL request can vary significantly. Since the API uses a single endpoint, it is difficult to figure out the complexity of each request before it has been served.
382388

@@ -405,7 +411,7 @@ Currently, you can only create complexity-based (or score-based) rules such as t
405411

406412
When the origin server processes a request, it adds a `score` HTTP header to the response with a value representing how much work the origin has performed to handle it — for example, `400`. In the next hour, the same client can perform requests up to an additional budget of `600`. As soon as this budget is exceeded, later requests will be blocked until the timeout expires.
407413

408-
### GraphQL malicious query protection
414+
### Limit any individual query’s complexity
409415

410416
API Shield customers can use GraphQL malicious query protection to protect their GraphQL APIs. GraphQL malicious query protection scans your GraphQL traffic for queries that could overload your origin and result in a denial of service. You can build rules that limit the query depth and size of incoming GraphQL queries in order to block suspiciously large or complex queries.
411417

0 commit comments

Comments
 (0)