The vulnerability exists in the /config/uploads API endpoint, which is handled by the fileUploadHandler function in internal/server/rest.go. This endpoint allows users to upload files either via a multipart form or by providing a URL in a JSON payload.
The root cause of the vulnerability is improper path validation. The application constructs file paths by concatenating a base directory with a user-provided filename using filepath.Join. However, filepath.Join does not prevent path traversal attacks (e.g., using ../). The resulting path is then passed to os.Create or os.OpenFile, which will write to any location on the filesystem that the user running the application has permissions for.
This vulnerability manifests in two code paths within fileUploadHandler:
- Multipart requests: The file writing logic is directly inside
fileUploadHandler.
- JSON requests: The logic is in the
getFile function, which is called by fileUploadHandler.
Both of these were vulnerable. An attacker could exploit this by sending a crafted filename to write files to arbitrary locations, potentially leading to Remote Code Execution (RCE) by overwriting system files like cron jobs or SSH keys.
A similar path traversal vulnerability was also present in the filex.UnzipTo function, used for plugin installation, which could be triggered by a maliciously crafted plugin zip file.
The patch addresses these issues by introducing a sandboxing mechanism. It uses a custom os.OpenRoot function to create a restricted (chroot-like) view of the filesystem, limited to the intended upload or plugin directory. All file creation operations (root.Create, root.OpenFile) are then performed within this sandbox, effectively preventing any writes outside of the designated directories.