Summary
R2R through version 3.6.6 contains a SQL injection vulnerability in the retrieval search endpoint. An unauthenticated attacker may manipulate the filter key parameter to inject SQL predicates, potentially enabling boolean-based or time-based extraction of database information.
Affected context
The vulnerability occurs in R2R retrieval searches when the endpoint accepts attacker-controlled filter keys and incorporates them into the chunks search query. Deployments are at risk where the endpoint is reachable by unauthenticated users and the application directly interpolates filter keys into a SQL WHERE clause without parameterization, escaping, or an equivalent allowlist.
Exploit preconditions
- Attack surface: The retrieval search endpoint that queries chunks
- Required access: Network access to the endpoint; authentication is not required according to the vulnerability description
- Trigger point: Processing the filter key parameter during construction of the search query
- Why exploitation is possible: User-controlled filter keys are inserted into SQL syntax without safe parameter binding or strict identifier validation
Why this happens
The underlying bug is SQL injection caused by treating a request-controlled filter key as trusted SQL syntax. Directly interpolating dynamic identifiers or predicates into a WHERE clause allows input to alter query logic rather than remain a data value. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, because application input is not adequately separated from executable database syntax.
Potential impact
- An attacker may infer database values through boolean-based responses
- An attacker could extract information using timing behavior
- Sensitive application or retrieval data may be exposed
- Database integrity or availability could be affected, depending on query privileges
- Compromised data may support follow-on attacks against connected services
General mitigation guidance
Mitigation generally focuses on separating user input from SQL syntax and reducing the trust placed in dynamic query components.
Common defensive patterns include:
- Using parameterized queries for all user-controlled values
- Restricting dynamic filter keys to a documented, fixed allowlist of valid fields
- Mapping external field names to server-defined database expressions rather than inserting them directly
- Applying strict input validation and rejecting unexpected operators or structural content
- Limiting the database account to the minimum read and write privileges required
- Avoiding detailed query errors and timing differences that disclose database behavior
How teams detect issues like this
Organizations can look for SQL injection risks through:
- Static analysis rules identifying string interpolation or concatenation in SQL construction
- Code review checks for request parameters used as column names, predicates, or clauses
- Dynamic testing that evaluates unexpected filter keys and response or timing differentials
- Web application firewall or API policy rules restricting unapproved query syntax
- Database monitoring for anomalous query patterns, repeated conditional probes, and unusual metadata access
Automated security review tools may help identify unsafe query-building patterns, but findings should be validated against the application's query abstraction and authorization model.

