<?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>Dgraph — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/vendors/dgraph/</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/vendors/dgraph/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 Unauthenticated Admin Token Disclosure via /debug/vars</title><link>https://feed.craftedsignal.io/briefs/2024-05-dgraph-auth-bypass/</link><pubDate>Thu, 02 May 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-05-dgraph-auth-bypass/</guid><description>Dgraph versions prior to 25.3.3 expose the admin token via the `/debug/vars` endpoint, allowing unauthenticated attackers to bypass authentication and gain administrative access.</description><content:encoded><![CDATA[<p>Dgraph, a graph database, exposes sensitive information through an unauthenticated endpoint, <code>/debug/vars</code>, in versions prior to 25.3.3. The vulnerability arises because the admin token is often passed as a command-line argument using the <code>--security &quot;token=...&quot;</code> flag. This argument is exposed through the <code>/debug/vars</code> endpoint, which is enabled by default via Go&rsquo;s <code>expvar</code> package. An attacker can retrieve this token without authentication and then use it to gain administrative privileges by including it in the <code>X-Dgraph-AuthToken</code> header of subsequent requests. This is a bypass of previous attempts to mitigate similar issues via <code>/debug/pprof/cmdline</code>, which were addressed incompletely. This issue impacts deployments where the Alpha HTTP port is reachable by untrusted parties, allowing for a full authentication bypass.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker sends an unauthenticated GET request to the <code>/debug/vars</code> endpoint on the Dgraph Alpha server (e.g., <code>GET /debug/vars HTTP/1.1</code>).</li>
<li>The server responds with a JSON payload containing the <code>cmdline</code> field.</li>
<li>The attacker parses the JSON response and extracts the value of the <code>cmdline</code> field.</li>
<li>The attacker searches the <code>cmdline</code> output for the <code>--security token=...</code> argument.</li>
<li>The attacker extracts the admin token from the <code>--security</code> argument string.</li>
<li>The attacker sends a request to an admin-only endpoint (e.g., <code>GET /admin/config/cache_mb HTTP/1.1</code>).</li>
<li>The attacker includes the extracted admin token in the <code>X-Dgraph-AuthToken</code> header of the request.</li>
<li>The Dgraph Alpha server validates the token, granting the attacker administrative access.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation allows an unauthenticated attacker to gain complete administrative control over the Dgraph database. This includes the ability to read and modify admin configurations, and perform operational control actions. In deployments where the Alpha HTTP port is publicly accessible, this vulnerability poses a significant risk, leading to potential data breaches, service disruption, and unauthorized manipulation of the database. While the number of affected deployments is not explicitly stated, any Dgraph instance running a vulnerable version with an exposed Alpha HTTP port is at risk.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade Dgraph to version 25.3.3 or later to address the vulnerability.</li>
<li>As a temporary workaround, restrict access to the Alpha HTTP port to trusted networks only.</li>
<li>Deploy the Sigma rule below to detect unauthorized access attempts to the <code>/admin/config/cache_mb</code> endpoint using the <code>X-Dgraph-AuthToken</code> header.</li>
<li>Deploy the Sigma rule below to detect access to <code>/debug/vars</code> endpoint.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>dgraph</category><category>authentication-bypass</category><category>admin-token-disclosure</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>