Summary
Cockpit v2.13.5 and earlier contains a code injection vulnerability where the filter parameter is interpreted in a way that permits execution of arbitrary system commands through the MongoLite $func operator.
An attacker who can send crafted requests to affected endpoints may be able to run commands on the underlying server, leading to full compromise of the hosting infrastructure.
Affected context
This vulnerability appears in Cockpit instances that:
- Expose endpoints accepting a
filterparameter backed by MongoLite queries - Allow the
$funcoperator to be passed directly from user input into query or function evaluation logic - Execute callbacks or command invocations derived from that operator within the server context
It is most relevant when Cockpit is reachable over a network (internet or internal) and when authentication and authorization controls do not fully constrain who can issue requests containing the filter parameter.
Exploit preconditions
- Attack surface: HTTP(S) endpoints in Cockpit that accept a
filterparameter processed by MongoLite - Required access: Ability to send crafted requests to those endpoints (may be unauthenticated or low-privileged depending on deployment configuration)
- Trigger point: Submission of a
filtervalue that leverages the$funcoperator to cause evaluation of attacker-controlled code or command strings - Why exploitation is possible: The server-side code treats parts of the
filterparameter, including$func, as executable logic rather than opaque data. This blurs the boundary between data and code, allowing injection and execution of commands in the application's execution environment.
Why this happens
The underlying bug belongs to the CWE-94: Improper Control of Generation of Code ('Code Injection') class.
In this pattern, user-provided input is fed into a mechanism that can generate or invoke executable logic (here, the MongoLite $func operator) without strict validation or restriction. Instead of handling the filter parameter as pure data for query construction, the application allows dynamic behaviors to be defined by the client. When these behaviors are interpreted on the server—such as function callbacks or shell commands—they execute with the privileges of the Cockpit process. The absence of strong whitelisting, sandboxing, or safe evaluation boundaries enables an attacker to transform a data field into an execution channel.
Potential impact
- Execution of arbitrary system commands on the host running Cockpit
- Full compromise of the Cockpit application and associated data
- Theft or modification of content, configuration, or credentials managed by Cockpit
- Pivoting to other internal services reachable from the compromised server
- Deployment of malware, backdoors, or cryptominers on the underlying infrastructure
- Interruption of service availability through destructive commands
General mitigation guidance
Effective mitigation focuses on preventing user input from being interpreted as executable logic and constraining any dynamic behaviors:
- Treat the
filterparameter and similar query fields as data-only, disallowing operators like$funcfrom being influenced by client input. - Apply strict whitelisting of allowed query operators and fields; reject or ignore anything not explicitly permitted.
- Avoid evaluation mechanisms that can invoke arbitrary code, shell commands, or untrusted callbacks; prefer fixed, parameterized query builders and static functions.
- Enforce input validation that normalizes and rejects structured input containing unexpected executable constructs.
- Run the Cockpit process with least privilege, using restricted OS accounts and limiting access to the filesystem and system utilities where practical.
- Consider introducing application-level policies that separate high-risk operations from routine query handling, or that constrain complex querying to trusted back-office flows.
How teams detect issues like this
Detection can combine code-centric and operational techniques:
- Static analysis and code review:
- Search for uses of MongoLite or similar libraries where client-controlled input influences operators like
$func. - Flag any code paths that evaluate or execute data from HTTP parameters, especially within query builders, callback resolution, or shell invocation routines.
- Review for generic "eval-like" behavior, dynamic function name resolution, or string-based command construction tied to request data.
- Configuration and policy checks:
- Enforce coding standards that ban execution of dynamically computed commands or function identifiers derived from request fields.
- Integrate automated code review tools or linters that detect unsafe dynamic evaluation patterns.
- Runtime and log analysis:
- Monitor application and system logs for abnormal query patterns involving
$funcor unexpected operators infilterparameters. - Alert on suspicious command execution behavior, such as unusual processes launched by the Cockpit service account.

