DoS Protection
The squid GraphQL API server accepts the following optional start arguments to fend off heavy queries. To enable the protection, add the corresponding flags toserve and serve:prod command definitions at commands.json:
serve:prod to start the GraphQL api service in the deployment manifest:
squid.yaml
Configuration flags
--max-request-size <kb>
The argument limits the size of a request in kilobytes. It is set to 256kb by default.
--max-root-fields <count>
The maximal allowed number of root-level queries in a single GraphQL request.
--max-response-size <nodes>
This option limits the estimated query response size and makes server return an error if it exceeds the provided value. Note that the estimated size depends only on the decorators in schema.graphql and the requested fields.
The estimate is the product of the cardinality of the entity list and the response item weight.
The cardinality is estimated as the minimum of:
- the
limitargument of the query (Infinityif not provided) @cardinalityvalue defined inschema.graphql(if the requested entity type is decorated in the schema file,Infinityotherwise)- the size of the argument list of the
_eqandid_infilters in thewhereclause (if applicable)
If there are no
@cardinality decorators in schema.graphql, the client
queries must explicitly provide limits or where filters to pass through.byteWeightfor each scalar field or1if it’s not decorated- for non-scalar fields, the estimated weight times the estimated cardinality (if it’s a list)
- each non-leaf node in the query AST tree adds a weight of
1
--subscription-max-response-size <nodes>
Same as --max-response-size but for live query subscriptions.
Example
Assume the schema is defined as follows, and the server is launched with--max-response-size 1000.
schema.graphql
- The estimated cardinality of query A is
Infinity - The estimated cardinality of query B
1001and so the expected size exceeds the limit - The estimated cardinality of query C is
100while the item size is13, so the size is estimated to1300. - The estimated cardinality of query D is
10while the item size is103, so the size is estimated to1030. - The estimated cardinality of query E is
1while the item size is1001(due tobigFieldhaving weight1000).

