Summary
Cockpit CMS contains an authenticated code injection flaw in the /cockpit/collections/save_collection endpoint that allows users with collection management privileges to inject arbitrary PHP into collection rules.
The injected PHP is written into server-side files and later executed via include(), enabling attackers to run arbitrary commands on the underlying server under the web server's privileges.
Affected context
This vulnerability affects Cockpit CMS deployments where authenticated users can manage or configure collections through the /cockpit/collections/save_collection endpoint.
The issue arises in environments where rule parameters from collection configurations are persisted to PHP files without strict validation or sanitization and are subsequently loaded via include() or similar constructs.
It is most relevant in multi-user or shared admin setups where collection management rights may be granted to non-owners or integrated systems.
Exploit preconditions
- Attack surface: HTTP interface of Cockpit CMS, specifically the
/cockpit/collections/save_collectionendpoint. - Required access: Valid authenticated account with permissions to create or modify collections (collection management privileges).
- Trigger point: Submission or update of collection configurations whose rule parameters are stored to PHP files and later loaded via
include(). - Why exploitation is possible: The application treats rule parameters as trusted content, writing them directly into executable PHP files without neutralizing code, and then executes them through
include(), giving attackers a path to inject and execute arbitrary PHP.
Why this happens
The core issue is improper neutralization of user-controllable input before it is incorporated into executable code, which aligns with CWE-94: Improper Control of Generation of Code ('Code Injection').
Cockpit CMS allows collection rule parameters, supplied by authenticated users, to be written directly into PHP files that are later evaluated via include().
This pattern effectively turns configuration input into application logic without strict separation or sanitization, meaning that any PHP code embedded in these parameters is executed in the server context.
The lack of a strict, non-executable format for rules and absence of robust validation or encoding of rule content leads to full code injection capabilities.
Potential impact
- Execution of arbitrary PHP code on the server
- Execution of arbitrary OS commands with the web server's privileges
- Reading, modifying, or deleting CMS data and configuration
- Access to credentials, API keys, or other secrets stored on the server
- Pivoting into internal networks reachable from the CMS host
- Complete takeover of the affected Cockpit CMS instance
General mitigation guidance
Effective mitigation focuses on treating rule definitions as data, not executable code, and minimizing the trust placed in configuration content:
- Use a non-executable representation (e.g., JSON, structured arrays, or a constrained expression language) for collection rules rather than embedding raw PHP.
- Implement strict validation and whitelisting for rule parameters, limiting them to well-defined, non-code constructs.
- Avoid
include()or similar dynamic-code-loading mechanisms for user-modifiable configuration; interpret rules with a fixed, non-eval-based engine. - Enforce principle of least privilege for CMS roles, granting collection management rights only to highly trusted accounts.
- Run the web server and PHP runtime with minimal OS privileges and restrict filesystem write access, especially to directories containing executable code.
- Consider using separate configuration and code directories, treating configuration paths as non-executable in the web and PHP configuration.
How teams detect issues like this
Organizations can detect and monitor for this class of weakness through a combination of code-focused and operational controls:
- Static analysis rules that flag:
- Use of
include(),require(), or similar functions with paths influenced by user input. - Construction of PHP files or dynamic code from request parameters or database-stored configuration.
- Code review checklists focusing on:
- Any flow where configuration or admin-defined rules are written to
.phpfiles. - Any mechanism where user-influenced data is treated as executable PHP.
- Runtime monitoring such as:
- File integrity monitoring for unexpected changes to PHP files in configuration or module directories.
- Logging and alerting on unusual admin activity related to collection creation or modification.
- Integration of automated security testing tools in CI pipelines that look for dynamic code generation and inclusion patterns.

