Summary
Dify's MyScale vector store backend contains a SQL injection flaw in the search_by_full_text method that allows arbitrary SQL execution via unsanitized search parameters.
When user-supplied search text is concatenated into ClickHouse queries without escaping or parameterization, attackers can inject SQL to read, modify, or delete data in the underlying database.
Affected context
This vulnerability occurs in Dify deployments that use the MyScale vector store backend and rely on the search_by_full_text method for full-text search.
It is relevant when user-controlled search parameters are passed directly into ClickHouse queries without parameter binding, escaping, or query construction safeguards.
Environments where the application has broad database privileges are more exposed, but the risk can exist in any setup that treats search text as trusted input.
Exploit preconditions
- Attack surface: Application interfaces that accept search text (e.g., API endpoints, UI search boxes) and route it into the MyScale
search_by_full_textcall. - Required access: Ability to submit search parameters to the affected method; typically unauthenticated or low-privilege user input is sufficient.
- Trigger point: Execution of dynamically built ClickHouse queries where search text is concatenated directly into the SQL string.
- Why exploitation is possible: The query builder does not use parameterized statements or proper escaping, allowing input to alter the query structure instead of being treated purely as data.
Why this happens
The underlying bug is classic SQL injection as described by CWE-89: Improper Neutralization of Special Elements used in an SQL Command.
The MyScale vector store backend constructs ClickHouse SQL queries by interpolating raw search parameters into the query string, assuming they are safe.
Because the application does not enforce separation between query logic and user data (e.g., via prepared statements or robust query builders), an attacker can include SQL control characters and syntax that the database interprets as part of the command.
This insecure pattern—forming SQL via string concatenation with untrusted input—allows attackers to override filters, join additional tables, or append destructive operations.
Potential impact
- Attackers may read sensitive data from ClickHouse tables beyond what the application normally exposes.
- Malicious queries could modify or delete stored vectors and metadata, degrading search quality or destroying records.
- Injected SQL can bypass application-level access controls and row-level filters where enforced only in the query logic.
- An attacker could tamper with analytics or logging data, leading to misleading insights or masking other attacks.
- If the database user has administrative privileges, configuration changes or broader data exfiltration can occur.
General mitigation guidance
Effective mitigation focuses on eliminating direct string concatenation of SQL with untrusted input and narrowing database privileges.
Recommended defensive patterns include:
- Adopting parameterized queries or prepared statements for all search operations, ensuring user input is always treated as data.
- Using vetted query builder libraries that abstract SQL construction and enforce safe interpolation.
- Applying strict input validation and normalization for search parameters, limiting allowed characters and patterns where feasible.
- Segmenting database privileges so the application role can only perform the minimal set of read/write operations required.
- Implementing least-privilege access to ClickHouse tables and views, and avoiding exposing raw base tables when derived views suffice.
- Designing search APIs to avoid passing raw user text directly into dynamic SQL clauses (such as ORDER BY, LIMIT, or arbitrary WHERE fragments).
How teams detect issues like this
Detection typically combines static analysis, code review, and runtime monitoring:
- Static analysis rules can flag SQL construction that uses string concatenation or interpolation with user-controlled variables, especially in data access layers.
- Code review processes should look for direct
SELECT ...strings that accept search text, ensuring prepared statements or query builders are used. - Security linters and CI policies can enforce patterns such as "no raw SQL with concatenated parameters" in specific modules (e.g., vector store backends).
- Database-level monitoring can detect anomalous queries, such as unexpected table access, UNIONs, or destructive operations originating from search-related endpoints.
- Automated application security testing (DAST) and fuzzing tools can be configured to probe search interfaces for injection behavior and unexpected error responses.

