Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: guard volume file browser against non-mountable driver types (#2364)
Giulio Savini2735b0bac387
diff --git a/backend/internal/services/volume_service.go b/backend/internal/services/volume_service.goindex 048f25850..ab495ad1d 100644--- a/backend/internal/services/volume_service.go+++ b/backend/internal/services/volume_service.go@@ -262,9 +262,27 @@ func buildVolumePruneMetadataInternal(all bool, volumesDeleted int, spaceReclaim// --- Volume Browsing & Backup ---+// isBrowsableVolumeInternal returns an error if the volume uses driver options+// that prevent it from being mounted inside a helper container, such as+// type=none or o=bind (host bind-mounts that require a device path on the host).+func (s *VolumeService) isBrowsableVolumeInternal(ctx context.Context, volumeName string) error {+ vol, err := s.GetVolumeByName(ctx, volumeName)+ if err != nil {+ return fmt.Errorf("failed to inspect volume: %w", err)+ }+ if vol.Options["type"] == "none" || strings.Contains(vol.Options["o"], "bind") {+ return fmt.Errorf("volume %q uses a custom mount configuration and cannot be browsed", volumeName)+ }+ return nil+}+func (s *VolumeService) ListDirectory(ctx context.Context, volumeName, dirPath string) ([]volumetypes.FileEntry, error) {slog.DebugContext(ctx, "volume service: list directory", "volume", volumeName, "path", dirPath)+ if err := s.isBrowsableVolumeInternal(ctx, volumeName); err != nil {+ return nil, err+ }+sanitizedPath, err := s.sanitizeBrowsePathInternal(dirPath)if err != nil {return nil, fmt.Errorf("invalid path: %w", err)@@ -348,6 +366,10 @@ func (s *VolumeService) ListDirectory(ctx context.Context, volumeName, dirPath sfunc (s *VolumeService) GetFileContent(ctx context.Context, volumeName, filePath string, maxBytes int64) ([]byte, string, error) {slog.DebugContext(ctx, "volume service: get file content", "volume", volumeName, "path", filePath, "max_bytes", maxBytes)+ if err := s.isBrowsableVolumeInternal(ctx, volumeName); err != nil {+ return nil, "", err+ }+sanitizedPath, err := s.sanitizeBrowsePathInternal(filePath)if err != nil {return nil, "", fmt.Errorf("invalid path: %w", err)@@ -375,6 +397,10 @@ func (s *VolumeService) GetFileContent(ctx context.Context, volumeName, filePathfunc (s *VolumeService) DownloadFile(ctx context.Context, volumeName, filePath string) (io.ReadCloser, int64, error) {slog.DebugContext(ctx, "volume service: download file", "volume", volumeName, "path", filePath)+ if err := s.isBrowsableVolumeInternal(ctx, volumeName); err != nil {+ return nil, 0, err+ }+sanitizedPath, err := s.sanitizeBrowsePathInternal(filePath)if err != nil {return nil, 0, fmt.Errorf("invalid path: %w", err)