Summary
Craft CMS has an SQL injection vulnerability in GraphQL eager-loading: arguments on eager-loadable nodes that are not in the public schema can be copied into query criteria without adequate cleansing. An unauthenticated attacker who can reach the affected GraphQL functionality may inject SQL expressions and read database contents, potentially including password hashes and session tokens.
Affected context
The issue affects Craft CMS GraphQL eager-loading in the specified 4.x and 5.x release ranges. It arises when arguments supplied for eager-loadable nodes that are absent from the public schema are incorporated into EagerLoadPlan criteria without cleansing. Risk depends on the affected GraphQL functionality being reachable and processing attacker-controlled queries.
Exploit preconditions
- Attack surface: GraphQL endpoint with eager-loading functionality
- Required access: The vulnerability is described as exploitable by unauthenticated attackers; no account is required when the endpoint is publicly reachable
- Trigger point: Processing a GraphQL query containing arguments on an eager-loadable node that are absent from the public schema
- Why exploitation is possible: Those arguments can flow into SQL criteria without adequate cleansing, allowing injected SQL expressions to affect database queries
Why this happens
The application incorporates attacker-controlled GraphQL arguments into eager-load query criteria without adequately validating or safely binding them. This is an SQL injection flaw mapped to CWE-89, which describes failure to neutralize special elements in SQL commands. The underlying insecure pattern is treating input outside the declared public schema as safe when constructing database queries.
Potential impact
- Attackers may read arbitrary database content accessible to the affected queries.
- Exposed records could include password hashes or session tokens.
- Stolen credentials or tokens could enable further account or application compromise.
General mitigation guidance
Defensive patterns focus on preventing untrusted values from changing SQL query structure:
- Use parameterized queries or safe query-builder APIs that bind values rather than concatenate SQL.
- Validate GraphQL arguments against an explicit schema and reject unsupported or unexpected fields.
- Avoid forwarding undeclared input into database criteria; reduce trust in client-supplied query data.
- Limit database account permissions to the minimum required and restrict access to sensitive records.
- Apply appropriate authentication, authorization, and exposure controls to GraphQL functionality.
These practices provide defense in depth without relying on input cleansing alone.
How teams detect issues like this
- Use static analysis to identify SQL construction involving untrusted GraphQL arguments, especially where string concatenation or raw expressions are used.
- Review eager-loading and query-builder code for paths that accept arguments absent from the public schema.
- Enforce code-review and CI policies requiring parameterized queries and explicit argument validation.
- Monitor GraphQL and database activity for unusual query patterns or unexpected access to sensitive tables.
- Automated code review tools may help flag unsafe query construction and inconsistent schema validation.

