Summary
Craft CMS front-end searches using craft.search may be vulnerable to unauthenticated SQL injection when the attribute parameter is incorporated into a database query unsafely. On MySQL or MariaDB, stacked queries may allow database reads and writes, including changes that could grant administrator privileges.
Affected context
The issue occurs in Craft CMS sites that use craft.search for front-end searches and run on MySQL or MariaDB. Risk depends on the vulnerable search handling being reachable by unauthenticated users; other database systems are not identified as affected by the description.
Exploit preconditions
- Attack surface: A front-end search endpoint that uses
craft.search - Required access: No authentication is required
- Trigger point: Processing a search request with an
attributeparameter - Database condition: The application uses MySQL or MariaDB
- Why exploitation is possible: The parameter is concatenated into a query unsafely, and emulated PDO prepares allow stacked statements to execute
Why this happens
The application incorporates the attribute parameter into SQL without adequate sanitization or safe parameterization. With emulated prepares, stacked statements may be executed, allowing input to alter query behavior. This is CWE-89: SQL Injection, caused by mixing untrusted input with SQL command structure.
Potential impact
- Unauthenticated attackers may read sensitive application database contents.
- Attackers could modify or overwrite database records, including account password hashes.
- An attacker may be able to change an account's administrator flag and gain elevated application privileges.
General mitigation guidance
Defensive approaches focus on keeping untrusted input out of SQL structure and limiting the consequences of a database query flaw. Common patterns include:
- Use parameterized queries with native prepares where supported, and avoid constructing SQL from request-controlled values.
- Map accepted search attributes to a strict server-side allowlist rather than accepting arbitrary column names.
- Validate requests against an explicit search schema and reject unexpected parameters.
- Apply least-privilege permissions to database accounts and separate application capabilities where practical.
- As a temporary filtering measure, consider blocking front-end requests containing
[attribute]in the query string while assessing exposure.
How teams detect issues like this
- Use static analysis to find SQL strings assembled with request parameters, especially in search and filtering code.
- Review database access paths for dynamically selected columns or other query structure derived from user input.
- Add tests that verify unexpected search attributes are rejected and query values remain parameterized.
- Apply request policies or monitoring to flag suspicious front-end search parameters and unexpected database writes.
- Automated code review tools may help identify unsafe query construction patterns.

