Limit scanned resources parsed for the GraphQL fields
What does this MR do and why?
Adds limits to the scannedResources and scannedResourcesCount GraphQL fields. They parse a pipeline's security reports in the web request, and nothing limits how much they parse. On GitLab.com, requests for these fields have already been killed by the 60-second request timeout.
Behind the scanned_resources_graphql_limits feature flag (disabled by default), when DAST or API fuzzing scanned resources are requested:
- Size and count limits. Before parsing,
Security::ReportSummaryServicechecks the pipeline's DAST and API fuzzing artifacts, including child pipelines. If they total more than 20 MB or number more than 100, the fields returnnullwith a GraphQL error, without downloading or parsing anything. - Rate limit.
scanned_resources_graphql: 60 pipelines per minute per user. Each pipeline whose scanned resources are requested counts once, including one then rejected as too large. Over the limit, the fields returnnullwith a GraphQL error.
The rest of the query still returns data, and the error tells clients why the fields are null. The thresholds are explained in https://gitlab.com/gitlab-org/gitlab/-/work_items/637250#note_4196332173.
Why fixed values, not configurable limits: these fields are used by a few API clients, and the limits sit well above their usage. The rate limit is documented as a non-configurable rate limit.
Not in this MR: a complexity cost to cap how many pipelines one query can request. A real client's query already uses 181 of the 250 complexity budget, so the cost needs its own design.
Follow-up: after this merges, update the scannedResources and scannedResourcesCount field descriptions to say they return null with an error over the scanned resources limits, and regenerate the GraphQL reference docs. It's fine as a follow-up because the limits are behind the scanned_resources_graphql_limits feature flag, which is off by default, so the fields don't change for anyone until the flag is enabled. The limits themselves are already documented on the instance limits and non-configurable rate limits pages.
Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/637250
How to set up and validate locally
- Enable the flag:
Feature.enable(:scanned_resources_graphql_limits). - Use a pipeline with a DAST report and query
securityReportSummary { dast { scannedResourcesCount vulnerabilitiesCount } }. It returns the count. - Make the report look larger than 20 MB:
Ci::JobArtifact.dast.last.update_column(:size, 21.megabytes). - Query again.
scannedResourcesCountisnull,vulnerabilitiesCountstill returns, anderrorsincludes "Scanned resources are too large to load for this pipeline."
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.