/

CVE-2026-29174

Severity:

HIGH RISK

(8.8)

SQL Injection in Craft Commerce Inventory Levels Sorting

CVE-2026-29174

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Database Compromise / Arbitrary SQL Execution

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 Commerce's inventory levels table endpoint builds an ORDER BY clause using user-controlled sorting parameters without validation, enabling SQL injection.

An authenticated attacker with access to the Commerce Inventory section can manipulate sort[0][direction] and sort[0][sortField] to run arbitrary SQL, which may lead to full database compromise.

Affected context

The vulnerability occurs in Craft Commerce installations where the inventory levels table data endpoint accepts sorting controls from authenticated users.

Specifically, the sort[0][direction] and sort[0][sortField] query parameters are concatenated into an addOrderBy() clause without robust validation.

This risk is present when backend code directly incorporates user-supplied sorting fields or directions into SQL fragments, especially ORDER BY clauses, rather than mapping them through a fixed, trusted list.

Exploit preconditions

  • Attack surface: HTTP(S) requests to the Craft Commerce backend, specifically the inventory levels table data endpoint.
  • Required access: Authenticated access to the Commerce Inventory section (e.g., staff or admin-level role with inventory viewing permissions).
  • Trigger point: Submission of crafted sort[0][direction] and/or sort[0][sortField] parameters that are incorporated into an addOrderBy() clause.
  • Why exploitation is possible: The application concatenates unvalidated user input directly into SQL used for ordering results, allowing injection of attacker-controlled SQL fragments that the database will parse and execute.

Why this happens

This issue stems from constructing SQL queries by concatenating user-controlled input into the ORDER BY clause without using parameterization or a strict mapping.

The sort[0][direction] and sort[0][sortField] parameters are treated as trusted fragments and passed to addOrderBy(), effectively embedding raw input into the query.

This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where application code fails to neutralize or constrain external input before using it in SQL statements.

Potential impact

  • An attacker could execute arbitrary SQL queries within the application's database context.
  • The database contents may be read, including sensitive customer and order information where present.
  • Data can potentially be modified, deleted, or corrupted, impacting inventory, orders, and configuration.
  • Application behavior may be altered by changing configuration or session-related data stored in the database.
  • In some environments, database-level compromise could be leveraged to gain further access to underlying infrastructure.

General mitigation guidance

Effective mitigation focuses on treating all query-building inputs as untrusted and constraining them before use:

  • Use parameterized queries or query builders that separate data values from SQL structure, even for ORDER BY and other dynamic clauses.
  • Restrict sortable fields to a predefined, server-side whitelist and map incoming sort keys to these known column names rather than using them directly.
  • Normalize and strictly validate sort direction values (e.g., only allowing 'ASC' or 'DESC' chosen from a fixed enumeration).
  • Encapsulate query construction in well-reviewed data access layers, avoiding ad-hoc string concatenation in controller or view code.
  • Apply the principle of least privilege to the database account so that, if injection occurs, the available damage is reduced.

How teams detect issues like this

Organizations can detect and monitor for this class of vulnerability using several approaches:

  • Static analysis: Configure SAST rules to flag direct string concatenation into SQL helpers (e.g., addOrderBy, where, orderByRaw) when any operand originates from HTTP parameters or request data.
  • Code review: During manual review, pay special attention to query construction around search, filtering, and sorting endpoints, verifying use of whitelists and parameterization.
  • Security testing: Incorporate automated SQL injection testing in QA and CI pipelines, focusing on non-obvious vectors like ORDER BY, GROUP BY, and LIMIT/OFFSET parameters.
  • Runtime monitoring: Use database query logging or application monitoring tools to detect anomalous or malformed SQL, such as unexpected UNION, subqueries, or multiple statements originating from UI-driven endpoints.

Sources

SourceLink
github.comgithub.com/craftcms/commerce/commit/094d69df24b925544f337c38e2ec1effcd5395c7
github.comgithub.com/craftcms/commerce/commit/a2ea853935ef03297ea1298bdb0d8c55ec5daf7b
github.comgithub.com/craftcms/commerce/security/advisories/GHSA-pmgj-gmm4-jh6j

Frequently asked

questions

Yes, if the Craft CMS control panel or Commerce backend is exposed over the network, an attacker who can authenticate and access the Commerce Inventory section can exploit the issue via crafted HTTP requests.

Not necessarily. The attacker needs a role that grants access to the Commerce Inventory section and the affected table endpoint; this may be a staff or manager role rather than full admin, depending on how permissions are configured.

The safest pattern is to eliminate all direct string concatenation of user-controlled sorting input by enforcing strict whitelists for sortable fields, normalizing sort directions, and relying on parameterized or framework-provided query builders that do not accept raw SQL fragments from requests.

Establish development standards that require parameterized queries, prohibit raw SQL assembly from request data, mandate server-side whitelisting for dynamic query elements (like sort fields), and integrate both static analysis and security-focused code review into the regular development workflow.

Find out what's already
exploitable in your codebase.