Summary
A SQL injection vulnerability in Craft CMS's ElementSearchController::actionSearch() endpoint allows authenticated control panel users to inject arbitrary SQL through search criteria parameters.
When user-controlled criteria such as criteria[where] or criteria[orderBy] are passed directly into query construction without proper neutralization, an attacker can perform boolean-based blind SQL injection to enumerate and extract database contents.
Affected context
This vulnerability occurs in Craft CMS instances where control panel access is granted to non-admin users and the ElementSearchController::actionSearch() endpoint is reachable.
It specifically affects search requests that pass complex criteria structures (e.g., criteria[where], criteria[orderBy], or similar query properties) into the element search mechanism.
The issue manifests when these parameters are not sanitized or overridden before being used to build database queries, allowing attacker-supplied fragments to influence the final SQL.
Exploit preconditions
- Attack surface: HTTP requests to the Craft CMS control panel, targeting the ElementSearchController search endpoint.
- Required access: Any authenticated control panel account; administrative privileges are not required.
- Trigger point: Submission of crafted search criteria parameters (
criteria[where],criteria[orderBy], or related properties) that are incorporated into SQL queries. - Why exploitation is possible: The controller does not apply the unset/neutralization logic that was added to a related controller, so user-controlled parameters are propagated directly into query builders, enabling attacker-controlled SQL fragments to modify query structure and logic.
Why this happens
The underlying bug is a classic SQL injection (CWE-89) arising from improper neutralization of special elements used in an SQL command.
The ElementSearchController::actionSearch() endpoint accepts nested criteria parameters intended to influence search behavior, but it fails to discard or strictly validate sensitive query-building properties such as where and orderBy.
As a result, the application effectively concatenates or maps untrusted input into SQL query components without using a safe abstraction or parameterization layer to constrain the values to data-only content.
This insecure pattern mirrors a previously fixed issue in another controller, but the defensive unset logic was not applied here, leaving a parallel injection path open.
Potential impact
- Full read access to database tables via boolean-based blind SQL injection.
- Extraction of sensitive user data, including credentials (hashed passwords), tokens, and personal information.
- Discovery of application internals such as configuration values, feature flags, and schema details.
- Potential pivoting to other weaknesses if sensitive secrets (e.g., API keys, connection strings) are stored in the database.
- Integrity impact, such as modification or deletion of content, where the database permissions and injection vector allow it.
General mitigation guidance
Effective mitigation focuses on constraining how user-controlled criteria influence database queries and ensuring that untrusted input cannot alter SQL structure:
- Treat all incoming criteria fields as untrusted and strictly whitelist which fields may affect query options (e.g., limit allowed sort fields and directions).
- Remove or ignore dangerous query-building properties (
where,orderBy, raw expressions) from request data before using them in query construction. - Use parameterized queries and ORM/query-builder APIs that separate data values from SQL syntax and avoid passing raw fragments.
- Normalize search behavior behind higher-level APIs that accept only safe, validated options instead of arbitrary query conditions.
- Apply the same secure-by-default patterns consistently across all controllers and endpoints that share similar query construction logic.
How teams detect issues like this
Detection efforts should concentrate on identifying untrusted parameters that flow into query construction and on monitoring for anomalous query behavior:
- Use static application security testing (SAST) to flag direct use of request parameters in
where,orderBy, or raw SQL expressions, especially in controller actions and search endpoints. - During code review, look for patterns where request criteria are mapped directly to query-builder methods without whitelisting or transformation.
- Enforce development policies requiring that only predefined, enumerated values may control ordering, filtering, and other SQL clauses.
- Monitor database logs and application logs for unusual patterns, such as highly complex predicates, excessive
ORchains, or repetitive, timing-focused queries that may indicate blind injection attempts. - Integrate automated review tools into CI pipelines to catch reintroductions of unchecked query criteria in new or refactored controllers.

