Dgraph Pre-Auth DQL Injection Vulnerability
A pre-authentication DQL injection vulnerability in Dgraph's `/mutate` endpoint, when ACL is disabled, allows attackers to exfiltrate the entire database by crafting a malicious `cond` field in an upsert mutation.
A critical vulnerability exists in Dgraph, a graph database, allowing unauthenticated attackers to perform full database exfiltration. This flaw resides within the /mutate endpoint, specifically when Access Control Lists (ACL) are disabled, which is the default configuration. By injecting malicious DQL queries via a crafted cond field in an upsert mutation, attackers can bypass authorization checks and extract sensitive data, including user credentials and secrets. The vulnerability stems from the lack of proper sanitization of the cond field, leading to direct concatenation into the DQL query string. This vulnerability was found in v25.3.0, but may exist in other versions as well.
Attack Chain
- The attacker sends an HTTP POST request to the
/mutate?commitNow=trueendpoint without any authentication headers (e.g.,X-Dgraph-AccessToken,X-Dgraph-AuthToken). - The
mutationHandlerinhttp.goextracts the request body and processes themutationsarray, including thecondfield, usingstrconv.Unquote. - The request proceeds to
edgraph.Server.QueryNoGrpc, where theCondvalue is copied verbatim todql.Mutation.Condinserver.go. - The
buildUpsertQueryfunction inserver.goperforms a simple string replacement (@ifto@filter) but otherwise concatenates the unsanitizedCondvalue into the DQL query. - The
dql.ParseWithNeedVarsparser processes the constructed DQL string, accepting the injected query blocks as valid DQL. - The
authorizeQueryfunction inaccess.goreturnsnilimmediately because ACL is disabled (AclSecretKey == nil), bypassing authorization checks. - The injected query block executes, traversing and extracting data from the database.
- The response, containing the exfiltrated data, is returned to the attacker via
http.go, effectively granting unauthorized access to sensitive information.
Impact
Successful exploitation of this vulnerability results in complete database exfiltration. Attackers can retrieve all nodes, predicates, and values within the Dgraph database, including sensitive data such as user credentials, API keys, and Personally Identifiable Information (PII). Given the default configuration of Dgraph lacking ACL enabled, this poses a significant risk to organizations relying on Dgraph for data storage. The injection can also manipulate upsert conditions, bypassing uniqueness constraints and conditional mutation logic.
Recommendation
- Enable ACL on all Dgraph instances and configure appropriate access controls to mitigate unauthorized data access.
- Implement the Sigma rule
Detect Dgraph DQL Injection in Mutation Endpointto identify potentially malicious requests to the/mutateendpoint. - Sanitize and validate user-supplied input, especially the
condfield in mutation requests, to prevent DQL injection attacks. - Monitor network traffic to detect suspicious POST requests to the
/mutateendpoint with unusual or unexpectedcondvalues. - Review and restrict network access to the Dgraph instance, limiting access only to authorized clients and networks.
Detection coverage 1
Detect Dgraph DQL Injection in Mutation Endpoint
criticalDetects potential DQL injection attempts in the Dgraph /mutate endpoint by looking for suspicious DQL syntax within the 'cond' field of the request body.
Detection queries are kept inside the platform. Get full rules →