From ff5aa8a03b7d49fdf5ab1fc3cb76b4d13eadce3c Mon Sep 17 00:00:00 2001 From: Kathryn Baldauf Date: Mon, 10 Aug 2026 13:42:16 -0700 Subject: [PATCH] Validate volume name in volume disk usage call (#2107) Signed-off-by: Kathryn Baldauf --- .../Server/Volumes/VolumesService.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Services/ContainerAPIService/Server/Volumes/VolumesService.swift b/Sources/Services/ContainerAPIService/Server/Volumes/VolumesService.swift index 3edd96e4..fe607e76 100644 --- a/Sources/Services/ContainerAPIService/Server/Volumes/VolumesService.swift +++ b/Sources/Services/ContainerAPIService/Server/Volumes/VolumesService.swift @@ -174,8 +174,7 @@ public actor VolumesService { ) } - let volumePath = self.volumePath(for: name) - return FileManager.default.allocatedSize(of: URL(fileURLWithPath: volumePath)) + return try await self._volumeDiskUsage(name) } /// Calculate disk usage for volumes @@ -403,4 +402,12 @@ public actor VolumesService { return volume } + private func _volumeDiskUsage(_ name: String) async throws -> UInt64 { + guard VolumeStorage.isValidVolumeName(name) else { + throw VolumeError.invalidVolumeName("invalid volume name '\(name)': must match \(VolumeStorage.volumeNamePattern)") + } + + let volumePath = self.volumePath(for: name) + return FileManager.default.allocatedSize(of: URL(fileURLWithPath: volumePath)) + } }