Summary
LangChain4j's MariaDB and pgvector embedding stores construct metadata filter SQL queries by string concatenation without adequate escaping of metadata keys and some values.
An attacker who can supply crafted metadata filters to EmbeddingSearchRequest.filter() may inject arbitrary SQL into search and removeAll(Filter) operations, enabling blind data exfiltration, denial of service, or deletion of arbitrary rows.
Affected context
This vulnerability appears in applications using LangChain4j's MariaDB or pgvector embedding stores where metadata-based filtering is supported.
It becomes relevant when user-controllable metadata keys or string values are passed into EmbeddingSearchRequest.filter() and then used to build SQL WHERE clauses via direct string concatenation.
The risk is higher in deployments where embedding stores share a database with other application tables, or where database accounts used by the stores have broad privileges beyond read-only access to embeddings.
Exploit preconditions
- Attack surface: API endpoints, services, or internal components that accept metadata filters for embedding search or deletion operations and forward them to LangChain4j embedding stores.
- Required access: Ability to create or manipulate EmbeddingSearchRequest.filter() contents, either directly through an SDK or indirectly via HTTP/JSON inputs or similar interfaces.
- Trigger point: Execution of search or removeAll(Filter) operations where filter keys and, for MariaDB, string values are concatenated into SQL statements without proper escaping or parameterization.
- Why exploitation is possible: The filter keys and some filter values are treated as trusted SQL fragments, not as data, allowing crafted input to break out of the intended comparison context and inject arbitrary SQL expressions or statements.
Why this happens
The underlying issue is the construction of SQL queries from untrusted input using dynamic string concatenation rather than parameterized statements.
In the MariaDB and pgvector embedding stores, metadata filter keys and, in the MariaDB case, string values are directly interpolated into SQL WHERE clauses without robust quoting or validation.
This pattern maps to CWE-89: SQL Injection, where user-controlled data is embedded into SQL commands in a way that allows alteration of the query's structure, making it possible to execute unintended commands against the database.
Potential impact
- Blind data exfiltration from embedding-related tables and potentially other tables accessible to the database user
- Denial of service by invoking sleep or resource-intensive SQL functions
- Deletion of arbitrary rows via crafted filters passed to removeAll(Filter)
- Unauthorized modification of metadata or embedding records if the database role permits updates
- Leveraging injected SQL to pivot to other schemas or administrative functions, depending on database privileges and configuration
General mitigation guidance
Effective mitigation focuses on separating untrusted data from SQL command structure and tightening database privileges.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all dynamic SQL, treating filter keys and values strictly as data rather than SQL fragments.
- Enforcing an allowlist of valid metadata keys and operators, rejecting or sanitizing anything that does not match expected identifiers.
- Applying strict validation and normalization on metadata values, avoiding direct interpolation into SQL clauses.
- Running embedding store database accounts with least privilege, limiting access to only the required tables and operations, and preferring read-only roles for search paths.
- Structuring application interfaces so that clients cannot directly influence raw SQL filter syntax, instead exposing higher-level filter abstractions that are safely translated into queries.
How teams detect issues like this
Detection typically combines code-level analysis with runtime monitoring:
- Static analysis rules that flag dynamic SQL construction using string concatenation, especially where input originates from EmbeddingSearchRequest.filter() or other user-facing parameters.
- Targeted code review focusing on repository modules that interact with MariaDB or pgvector embedding stores, checking for lack of parameterization and missing identifier/value validation.
- Security testing that attempts SQL injection payloads via metadata filters and observes for anomalous behavior, such as unexpected errors, timing differences, or altered query results.
- Database monitoring and logging to detect suspicious queries, including those containing sleep functions, concatenated literals, or unusual WHERE clauses, and correlating them with application requests.
- Integration of automated scanning tools or linters into CI/CD pipelines to enforce policies against constructing SQL queries via direct string concatenation.

