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()inlib/MongoLite/Aggregation/Optimizer.phpwithout 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=1published-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.

