Summary
A SQL injection vulnerability in Rucio's DID search endpoint allows any authenticated user to inject arbitrary SQL into the backend Oracle database when JSON metadata filters are used.
Because attacker-controlled filter keys and values are interpolated directly into sqlalchemy.text() via Python string formatting, parameterization is bypassed and an attacker can execute arbitrary queries, potentially compromising all managed data identifiers and sensitive account data.
Affected context
This vulnerability occurs in Rucio deployments that:
- Use Oracle as the backend database
- Enable the default
json_metaplugin for DID metadata - Expose the DID search endpoint
GET /dids/<scope>/dids/searchto authenticated users - Rely on
FilterEngine.create_sqla_query()to build SQL for JSON metadata filters
It does not affect PostgreSQL or MySQL deployments using the same plugin, as the vulnerable query construction logic is Oracle-specific.
Exploit preconditions
- Attack surface: Rucio HTTP API endpoint
GET /dids/<scope>/dids/search - Required access: Any authenticated Rucio account with permission to call the DID search API
- User-controlled input: Filter keys and values in the query parameters that are passed to the
json_metafilter engine - Trigger point: Construction of Oracle JSON metadata filter expressions in
FilterEngine.create_sqla_query()usingsqlalchemy.text()combined with Python.format() - Why exploitation is possible: The code treats attacker-controlled strings as trusted SQL fragments, embedding them directly into
text()calls without parameter binding or escaping.sqlalchemy.text()assumes its input is already-safe SQL, so database-level protections are not applied to these fragments.
Why this happens
The root cause is unsafe dynamic SQL construction that directly concatenates untrusted input into query text, matching CWE-89: SQL Injection.
In the vulnerable Oracle code path, the filter engine builds JSON metadata predicates using Python string formatting (.format()) to substitute user-supplied key and value parameters into a sqlalchemy.text() template. Unlike parameterized queries, this pattern embeds the data as executable SQL syntax, giving an attacker control over the structure of the query. Because text() does not perform escaping or parameterization, the database executes the combined string as-is, allowing arbitrary SQL to be injected wherever these predicates are used.
Potential impact
- Extraction of sensitive tables such as:
- Identities and authentication tokens
- User accounts and associated metadata
rse_settings,rules, and other configuration data- All managed data identifiers (DIDs) and their metadata
- Modification or deletion of database contents, potentially impacting:
- Data integrity for rules, replicas, and transfers
- Account quotas, permissions, and settings
- JSON metadata associated with DIDs
- Creation of backdoor data entries to facilitate long-term persistence
- Use of database-level privileges to pivot to other systems that trust the Rucio database
General mitigation guidance
Effective mitigation focuses on eliminating unsafe query construction and tightening trust boundaries around query parameters:
- Use parameterized queries exclusively: Build filters with SQLAlchemy's expression APIs or bound parameters instead of formatting SQL strings. Ensure
keyandvalueare always passed as parameters, never interpolated into SQL text. - Avoid raw
text()for user input: Restrict use ofsqlalchemy.text()to static, non-user-influenced statements. When dynamic behavior is required, compose expressions via the ORM or Core expression language rather than manual string concatenation. - Constrain metadata filters: Introduce strict allow-lists for permissible JSON metadata keys, and enforce type constraints on values (e.g., numeric vs. string) before they are used in query construction.
- Validate and normalize inputs: Apply schema-level validation to filter parameters, rejecting malformed or unexpected patterns rather than attempting to sanitize them into safe SQL.
- Apply least-privilege at the database level: Configure the Rucio database user with only the minimal set of privileges needed, limiting the blast radius if a query is compromised.
- Harden API exposure: Where feasible, restrict access to sensitive search functionality via role-based access control, network segmentation, or dedicated gateways with additional input controls.
How teams detect issues like this
Detection can combine code-centric and operational approaches:
- Static analysis: Configure SAST rules to flag:
- Calls to
sqlalchemy.text()that include string formatting (%,.format(), f-strings) or concatenation with variables - Any raw SQL construction that incorporates HTTP parameters or request data
- Code review patterns: During reviews, treat any manual SQL string construction as a risk indicator. Require use of SQLAlchemy expression APIs and explicit parameter binding, and document any justified exceptions.
- Policy enforcement in CI/CD: Add automated checks that block merges when new instances of unsafe SQL patterns are introduced. This can be done via linters, grep-based rules, or custom CI jobs integrated with static analyzers.
- Runtime monitoring: Enable database auditing or query logging to detect unusual or complex statements issued from the Rucio application account, such as UNION-based queries, stacked statements (where supported), or attempts to read security-critical tables.
- Periodic security reviews: Regularly review critical API endpoints that accept complex filter expressions or search parameters, as these tend to be high-risk vectors for injection flaws.

