From 69a12fadcf1d30b5f5cd2916291836a20ebc15d7 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 7 May 2021 22:57:59 +0200 Subject: [PATCH] Resolve CA5389 --- .editorconfig | 1 - ArchiSteamFarm/ASF.cs | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 58cc021a8..631205fd4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -115,7 +115,6 @@ dotnet_diagnostic.ca1028.severity = silent dotnet_diagnostic.ca1031.severity = silent # TODO - one at a time -dotnet_diagnostic.ca5389.severity = silent dotnet_diagnostic.ca5392.severity = silent dotnet_diagnostic.ca5394.severity = silent diff --git a/ArchiSteamFarm/ASF.cs b/ArchiSteamFarm/ASF.cs index 1aecf3e27..1bd7c07ab 100644 --- a/ArchiSteamFarm/ASF.cs +++ b/ArchiSteamFarm/ASF.cs @@ -1004,7 +1004,11 @@ namespace ArchiSteamFarm { // Now enumerate over files in the zip archive, skip directory entries that we're not interested in (we can create them ourselves if needed) foreach (ZipArchiveEntry zipFile in archive.Entries.Where(zipFile => !string.IsNullOrEmpty(zipFile.Name))) { - string file = Path.Combine(targetDirectory, zipFile.FullName); + string file = Path.GetFullPath(Path.Combine(targetDirectory, zipFile.FullName)); + + if (!file.StartsWith(targetDirectory, StringComparison.Ordinal)) { + throw new InvalidOperationException(nameof(file)); + } if (File.Exists(file)) { // This is possible only with files that we decided to leave in place during our backup function