Summary
Cockpit versions 2.13.5 and earlier contain a misconfiguration in the Bucket component's _isFileTypeAllowed function that allows crafted filenames to bypass the extension filter.
An authenticated attacker can exploit this behavior to rename arbitrary files to use a .php extension, potentially enabling arbitrary code execution on the underlying server when those files are interpreted by PHP.
Affected context
The vulnerability occurs in deployments using the Cockpit CMS Bucket component where file type checks rely on filename-based extension filtering.
It becomes relevant when:
- PHP is enabled on the web server and
.phpfiles are executable - Buckets accept user-controlled uploads or file renames from authenticated users
- The
_isFileTypeAllowedfunction is the primary gate for determining which file types are permitted
In such environments, bypassing this filter allows dangerous server-side executable files to be created or renamed into a web-accessible location.
Exploit preconditions
- Attack surface: Web interface or API endpoints that expose the Cockpit Bucket component's upload or rename functionality.
- Required access: Valid authenticated account with permission to upload, manage, or rename files within a Bucket.
- Trigger point: Supplying a specially crafted filename to the Bucket component such that
_isFileTypeAllowedincorrectly treats it as allowed, resulting in a.phpfile being created or renamed. - Why exploitation is possible: The file type validation logic focuses on extension checks that can be bypassed by manipulating the filename (e.g., through multiple extensions, special characters, or encoding quirks), allowing disallowed executable types to pass as permitted formats.
Why this happens
The root cause is a flawed file type validation mechanism consistent with CWE-434: Unrestricted Upload of File with Dangerous Type.
Instead of reliably determining the file's true type or enforcing a deny-by-default policy for executable content, the _isFileTypeAllowed function relies on fragile, filename-based extension filtering.
This pattern fails when attacker-controlled filenames can be crafted to evade the extension checks, enabling the creation or renaming of files with a .php extension in a context where the web server executes them.
Potential impact
- Execution of arbitrary PHP code on the web server within the privileges of the web application process
- Full compromise of the Cockpit CMS instance and its data
- Pivoting to other services or systems reachable from the compromised server
- Installation of web shells or backdoors for persistent access
- Tampering with website content or data stored in Cockpit
General mitigation guidance
Effective mitigation focuses on hardening file handling and reducing trust in user-controlled filenames:
- Enforce a strict allowlist of safe, non-executable file types based on content (MIME type, magic bytes) rather than only on file extensions.
- Reject or strip executable extensions (e.g.,
.php,.php5,.phtml,.phar) for all user-uploaded or renamed files, even if they pass other filters. - Store user-supplied files outside of web-accessible directories, serving them through an application layer that does not execute them.
- Normalize filenames (e.g., lowercase, remove special characters and multiple extensions) before validation to prevent bypass via obfuscation.
- Apply least-privilege server configuration: disable execution of scripts in upload directories and restrict PHP handlers where feasible.
How teams detect issues like this
High-level detection can combine code-level analysis with runtime monitoring:
- Static analysis and code review:
- Flag code paths where file type checks rely primarily on
pathinfo, string suffix checks, or regular expressions against filenames. - Identify upload or rename handlers that allow
.phpor other executable extensions, or that use weak allowlists/denylists. - Review storage paths to confirm whether user-controllable files are placed under web-executable directories.
- Runtime and operational monitoring:
- Log and alert on uploads or renames resulting in files with executable extensions (e.g.,
.php) under web roots. - Monitor web server logs for unusual access patterns to newly created
.phpfiles or unexpected PHP endpoints. - Policy and tooling:
- Enforce secure file upload policies in CI/CD, using SAST/linters to detect unsafe validation patterns.
- Use web application firewalls or reverse proxies to block requests to suspicious script locations commonly used for web shells.

