/

CVE-2026-25495

Severity:

HIGH RISK

(8.8)

SQL Injection in Craft CMS element-indexes/get-elements

CVE-2026-25495

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Execution within Database Context

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Craft CMS contains a SQL injection vulnerability in the element-indexes/get-elements endpoint where the criteria[orderBy] parameter from the JSON body is used directly in an ORDER BY clause without proper sanitization.

An attacker with Control Panel access can inject arbitrary SQL into the query's ordering logic by manipulating this parameter, potentially leading to data exposure, logic tampering, or broader compromise of the application's database.

Affected context

The vulnerability exists in Craft CMS installations that expose the element-indexes/get-elements endpoint and accept JSON request bodies containing a criteria[orderBy] parameter.

It is relevant when:

  • Users have authenticated Control Panel access and can trigger element index queries
  • The backend constructs SQL queries dynamically from request parameters
  • The criteria[orderBy] field is interpolated into the SQL ORDER BY clause without using safe parameterization or whitelisting

Exploit preconditions

  • Attack surface: HTTP(S) API endpoint element-indexes/get-elements in Craft CMS.
  • Required access: Valid Control Panel account with sufficient permission to access element indexes.
  • Input vector: JSON body parameter criteria[orderBy], especially when viewState[order] is omitted or set to the same payload.
  • Trigger point: Backend processing of the request constructs an SQL query and directly inserts the orderBy value into the ORDER BY clause.
  • Why exploitation is possible: The application trusts the orderBy value as safe SQL syntax and concatenates it into the query string instead of enforcing strict whitelisting of sortable columns or using structured query building mechanisms.

Why this happens

This issue stems from dynamically building SQL queries using user-controlled data in the ORDER BY clause without proper validation or use of safe query construction patterns.

Instead of restricting criteria[orderBy] to a predefined set of allowed column names and directions, or mapping it through a safe abstraction, the application incorporates it directly into the SQL string.

This pattern falls under CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where special characters and SQL fragments from user input are not neutralized, allowing the attacker to alter the structure and semantics of the query.

Potential impact

  • Extraction of sensitive data by manipulating queries to reveal unintended records or metadata
  • Tampering with application logic that depends on query ordering or conditional clauses
  • Discovery of database schema details (table/column names) through crafted payloads
  • Potential chaining with other weaknesses (e.g., misconfigured database permissions) to modify or delete data
  • Increased risk of privilege escalation if database contents (such as credential hashes or API keys) are exposed

General mitigation guidance

Effective mitigation focuses on eliminating the ability for user input to shape raw SQL syntax:

  • Restrict orderBy input to a strict whitelist of known, safe column identifiers and directions, mapping user-friendly values to internal constants.
  • Use query builder abstractions or ORM mechanisms that represent ordering as structured data rather than as raw SQL fragments.
  • Avoid concatenating ORDER BY expressions directly; instead, validate that requested fields correspond to allowed model attributes and that sort directions are limited to known values (e.g., ASC, DESC).
  • Apply a defense-in-depth approach by minimizing database privileges for the application account and avoiding granting unnecessary write or administrative permissions.
  • Centralize query construction patterns so that parameter handling, validation, and sanitization are consistent across endpoints.

How teams detect issues like this

Detection typically involves both preventative and reactive approaches:

  • Static analysis rules that flag dynamic SQL construction, especially where request parameters influence ORDER BY, GROUP BY, or other structural clauses.
  • Secure code review checklists that call out any direct use of user-provided values in query fragments, with special attention to sorting or filtering criteria.
  • Logging and monitoring of database queries for anomalous patterns, such as unexpected keywords or complex expressions in ORDER BY clauses originating from application traffic.
  • Integration of automated security testing (e.g., SAST/DAST tools) into CI/CD pipelines to surface SQL injection patterns in routes that accept JSON bodies and construct queries dynamically.

Sources

SourceLink
github.comgithub.com/craftcms/cms/commit/96c60d775c644ff0a0276da52fe29e11d4cd38d2
github.comgithub.com/craftcms/cms/releases/tag/5.8.22
github.comgithub.com/craftcms/cms/security/advisories/GHSA-2453-mppf-46cj

Frequently asked

questions

Yes, it can be triggered remotely if the Craft CMS Control Panel is accessible over the network and an attacker can authenticate, but it is not exploitable by unauthenticated users by default.

The attacker must possess valid Control Panel credentials with permission to access element indexes and invoke the element-indexes/get-elements endpoint. They do not need direct database access; the application acts as the conduit.

Replace dynamic SQL concatenation with structured query building that maps user input to a predefined set of allowed fields and directions. All ordering options should be whitelisted and resolved server-side, ensuring that user input cannot introduce raw SQL fragments into the query.

Adopt secure coding standards that prohibit direct inclusion of user-controlled data in SQL syntax, enforce centralized validation of query parameters, use ORMs or query builders consistently, and incorporate automated security checks and peer review focused on input handling and query construction.

Find out what's already
exploitable in your codebase.