<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Dql-Injection — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/dql-injection/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata — refreshed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Sat, 26 Oct 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/dql-injection/feed.xml" rel="self" type="application/rss+xml"/><item><title>Dgraph Pre-Auth DQL Injection Vulnerability</title><link>https://feed.craftedsignal.io/briefs/2024-10-dgraph-dql-injection/</link><pubDate>Sat, 26 Oct 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-10-dgraph-dql-injection/</guid><description>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.</description><content:encoded><![CDATA[<p>A critical vulnerability exists in Dgraph, a graph database, allowing unauthenticated attackers to perform full database exfiltration. This flaw resides within the <code>/mutate</code> endpoint, specifically when Access Control Lists (ACL) are disabled, which is the default configuration. By injecting malicious DQL queries via a crafted <code>cond</code> 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 <code>cond</code> 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.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>The attacker sends an HTTP POST request to the <code>/mutate?commitNow=true</code> endpoint without any authentication headers (e.g., <code>X-Dgraph-AccessToken</code>, <code>X-Dgraph-AuthToken</code>).</li>
<li>The <code>mutationHandler</code> in <code>http.go</code> extracts the request body and processes the <code>mutations</code> array, including the <code>cond</code> field, using <code>strconv.Unquote</code>.</li>
<li>The request proceeds to <code>edgraph.Server.QueryNoGrpc</code>, where the <code>Cond</code> value is copied verbatim to <code>dql.Mutation.Cond</code> in <code>server.go</code>.</li>
<li>The <code>buildUpsertQuery</code> function in <code>server.go</code> performs a simple string replacement (<code>@if</code> to <code>@filter</code>) but otherwise concatenates the unsanitized <code>Cond</code> value into the DQL query.</li>
<li>The <code>dql.ParseWithNeedVars</code> parser processes the constructed DQL string, accepting the injected query blocks as valid DQL.</li>
<li>The <code>authorizeQuery</code> function in <code>access.go</code> returns <code>nil</code> immediately because ACL is disabled (<code>AclSecretKey == nil</code>), bypassing authorization checks.</li>
<li>The injected query block executes, traversing and extracting data from the database.</li>
<li>The response, containing the exfiltrated data, is returned to the attacker via <code>http.go</code>, effectively granting unauthorized access to sensitive information.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>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.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Enable ACL on all Dgraph instances and configure appropriate access controls to mitigate unauthorized data access.</li>
<li>Implement the Sigma rule <code>Detect Dgraph DQL Injection in Mutation Endpoint</code> to identify potentially malicious requests to the <code>/mutate</code> endpoint.</li>
<li>Sanitize and validate user-supplied input, especially the <code>cond</code> field in mutation requests, to prevent DQL injection attacks.</li>
<li>Monitor network traffic to detect suspicious POST requests to the <code>/mutate</code> endpoint with unusual or unexpected <code>cond</code> values.</li>
<li>Review and restrict network access to the Dgraph instance, limiting access only to authorized clients and networks.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>dgraph</category><category>dql-injection</category><category>injection</category><category>database-exfiltration</category></item><item><title>Dgraph Pre-Auth Full Database Exfiltration via DQL Injection</title><link>https://feed.craftedsignal.io/briefs/2024-01-dgraph-dql-injection/</link><pubDate>Wed, 03 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-dgraph-dql-injection/</guid><description>A pre-authentication DQL injection vulnerability in Dgraph's default configuration allows attackers to exfiltrate the entire database by crafting malicious JSON mutations to the `/mutate` endpoint, exploiting unsanitized language tags in predicates.</description><content:encoded><![CDATA[<p>A critical vulnerability in Dgraph, specifically within the <code>addQueryIfUnique</code> function, enables unauthenticated attackers to perform full database exfiltration. This affects default configurations where Access Control Lists (ACLs) are disabled. The attack involves sending crafted HTTP POST requests to the <code>/alter</code> and <code>/mutate</code> endpoints on port 8080. The vulnerability stems from the lack of sanitization of the <code>Lang</code> field in JSON mutations, which allows for DQL injection. By exploiting the <code>x.PredicateLang()</code> function, which splits predicate names on <code>@</code>, attackers can inject malicious code into the language tag. This injected code allows attackers to execute arbitrary DQL queries, bypassing authentication mechanisms and extracting sensitive data from the database. This vulnerability was tested on Dgraph version v25.3.0, posing a significant risk to organizations using Dgraph with default settings.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>The attacker sends an HTTP POST request to the <code>/alter</code> endpoint to create a schema predicate with <code>@unique @index(exact) @lang</code>. No authentication is required in the default Dgraph configuration.</li>
<li>The attacker crafts a JSON mutation containing a malicious payload. The key in the JSON mutation includes the predicate name followed by <code>@</code> and the DQL injection payload in the language tag position, such as <code>name@en,&quot;x&quot;)) leak(func: has(dgraph.type)) { uid dgraph.type name email secret aws_access_key_id aws_secret_access_key } } #</code>.</li>
<li>The attacker sends the crafted JSON mutation via an HTTP POST request to the <code>/mutate?commitNow=true</code> endpoint.</li>
<li>The <code>mutationHandler</code> parses the JSON body and identifies the malicious predicate and language tag.</li>
<li>The <code>x.PredicateLang</code> function splits the key on the last <code>@</code>, separating the predicate and the injection payload.</li>
<li>The <code>addQueryIfUnique</code> function constructs a DQL query string by interpolating the raw language tag from the mutation into the query via <code>fmt.Sprintf</code> without any sanitization.</li>
<li>The constructed DQL is parsed, and the injected query is executed, bypassing authentication checks due to <code>AclSecretKey == nil</code>.</li>
<li>The results of the injected query, containing the entire database content, are returned to the attacker in the HTTP response.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability allows an unauthenticated attacker to exfiltrate the entire Dgraph database, including all nodes, predicates, and values. This could lead to severe data breaches, exposure of sensitive information, and potential compromise of user credentials, API keys, or other confidential data stored within the database. The vulnerability affects Dgraph instances using the default configuration without ACL enabled, which poses a high risk to a wide range of deployments across various sectors.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Deploy the following Sigma rule to detect DQL injection attempts by monitoring for unusual characters and patterns in the <code>predicateName</code> field (within application logs or network traffic capturing HTTP POST requests) to the <code>/mutate</code> endpoint.</li>
<li>Enable ACL in Dgraph to require authentication for <code>/alter</code> and <code>/mutate</code> endpoints, mitigating the pre-authentication aspect of the vulnerability.</li>
<li>Implement input validation and sanitization for the <code>Lang</code> field in JSON mutations to prevent DQL injection, focusing on the <code>x.PredicateLang</code> function and <code>addQueryIfUnique</code> function within <code>edgraph/server.go</code>.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>dgraph</category><category>dql-injection</category><category>vulnerability</category></item></channel></rss>