/

CVE-2026-31891

Severity:

HIGH RISK

(7.7)

SQL Injection in Cockpit CMS MongoLite Aggregation Optimizer

CVE-2026-31891

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Unauthorized Data Access via SQL Injection

Severity:

HIGH RISK

(7.7)

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

Cockpit CMS up to version 2.13.4 contains a SQL injection vulnerability in the MongoLite Aggregation Optimizer backing the /api/content/aggregate/{model} endpoint.

When API access is enabled and this endpoint is reachable by untrusted users, an attacker with only a read‑only API key can inject arbitrary SQL via crafted field names, bypassing published-content filters and reading unauthorized data from the underlying SQLite database.

Affected context

The vulnerability exists in Cockpit CMS deployments that:

  • Run version 2.13.4 or earlier
  • Have API access enabled
  • Expose /api/content/aggregate/{model} to the internet or otherwise to untrusted clients
  • Use the MongoLite storage layer backed by SQLite for content data

In these conditions, aggregation requests containing malicious field names can reach the MongoLite Aggregation Optimizer without sufficient sanitization.

Exploit preconditions

  • Attack surface: HTTP(S) API endpoint /api/content/aggregate/{model}.
  • Required access: Possession of any valid Cockpit API key with read-only permissions; no administrator or write access is required.
  • Input vector: User-controlled aggregation query parameters where field names are reflected into SQL expressions by the MongoLite Aggregation Optimizer.
  • Trigger point: Processing of aggregation queries that invoke toJsonExtractRaw() in lib/MongoLite/Aggregation/Optimizer.php without applying the necessary field-name sanitization.
  • Why exploitation is possible: The optimizer composes SQLite JSON extraction expressions using field names that are not rigorously validated or escaped, allowing crafted values to alter the intended SQL query structure (CWE-89).

Why this happens

This issue stems from improper neutralization of user-controlled field names before they are interpolated into SQL fragments generated by the MongoLite Aggregation Optimizer.

The toJsonExtractRaw() method accepted field identifiers and transformed them into SQLite JSON extraction expressions without applying the same canonicalization and sanitization logic that had been added to other related paths (such as toJsonPath()).

As a result, an attacker could supply specially crafted "field names" in aggregation requests that, when processed, changed the structure of the resulting SQL query rather than being treated as inert identifiers, matching the classic pattern of CWE-89: Improper Neutralization of Special Elements used in an SQL Command.

Potential impact

  • Bypass of the _state=1 published-content filter to read drafts, unpublished entries, or restricted content.
  • Extraction of sensitive or internal data from the underlying SQLite content database that is not normally exposed through the public API.
  • Expansion of data visibility for low-privilege API keys beyond their intended authorization scope.
  • Assistance to attackers in mapping content schemas and internal structures that might support further attacks against the application or its integrations.

General mitigation guidance

Effective mitigation focuses on strict separation between user input and SQL command structure and on tightening API exposure:

  • Normalize and sanitize all field names used in query generation, applying consistent canonicalization rules to every path that constructs JSON extraction or other dynamic SQL fragments.
  • Prefer parameterized queries and explicit whitelists of allowed field identifiers, so that unrecognized or malformed fields are rejected before query building.
  • Treat aggregation request parameters as untrusted input, applying schema-based validation that enforces expected patterns (e.g., allowed characters, known field sets) rather than relying on ad-hoc checks.
  • Restrict exposure of /api/content/aggregate/{model} to trusted callers where possible, for example by placing it behind an internal network boundary or authenticated gateway.
  • Apply least-privilege principles to API keys, ensuring that read-only keys are scoped to the minimal models and operations necessary for their use.

How teams detect issues like this

Detection can rely on both code-centric and operational techniques:

  • Static analysis and code review:
  • Search for dynamic SQL construction in the MongoLite layer, particularly around JSON extraction helpers such as toJsonExtractRaw() and similar methods.
  • Flag any code paths that concatenate field names or other user-controlled strings directly into SQL expressions without prior validation or escaping.
  • Review API controllers handling /api/content/aggregate/{model} to ensure they apply strict schemas and do not pass arbitrary structures directly into the optimizer.
  • Automated tooling:
  • Configure static application security testing (SAST) rules for SQL injection sinks within PHP/SQLite integration points.
  • Use linters or custom checks that enforce identifier whitelisting for ORM or query-builder helpers.
  • Runtime and logging:
  • Monitor database logs and application logs for anomalous aggregation queries, including unexpected SQL syntax or malformed JSON extraction paths.
  • Set up alerting on repeated failed or unusually complex aggregation requests coming from low-privilege API keys.

Sources

SourceLink
github.comgithub.com/Cockpit-HQ/Cockpit/releases/tag/2.13.5
github.comgithub.com/Cockpit-HQ/Cockpit/security/advisories/GHSA-7x5c-vfhj-9628

Frequently asked

questions

Yes. If the /api/content/aggregate/{model} endpoint is exposed to the internet or any untrusted network and API keys can be obtained or misused, an attacker can exploit the vulnerability remotely through crafted HTTP requests.

Only a valid read-only API key is required. Administrative or write access is not necessary, making even the lowest-privilege API credentials sufficient to trigger the SQL injection.

The safest pattern is to ensure that all dynamic SQL fragments derived from user input are either eliminated or strictly controlled: validate and canonicalize field names against a whitelist, use parameterized queries where possible, and apply the same sanitization logic consistently across all helper methods that participate in query generation.

Adopt a defensive design where query builders never accept raw user-controlled identifiers without validation, enforce centralized input-validation utilities for fields used in database queries, include SQL injection checks in code review and SAST pipelines, and limit public exposure of powerful aggregation endpoints to the smallest necessary audience.

Find out what's already
exploitable in your codebase.