Skip to content

Commit b4ee2d9

Browse files
author
Admin user
committed
security updates
1 parent f47d517 commit b4ee2d9

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/Application/src/RazorPagesTestSample/Pages/Index.cshtml.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,14 @@ public async Task<IActionResult> OnPostAnalyzeMessagesAsync()
9494

9595

9696

97-
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory)
98-
{
99-
// Get the full path of the destination file
100-
string destFileName = Path.Combine(destDirectory, entry.FullName);
101-
102-
// Ensure the destination directory exists
103-
Directory.CreateDirectory(Path.GetDirectoryName(destFileName));
104-
105-
// Check if the destination file path is within the intended directory
106-
if (!destFileName.StartsWith(Path.GetFullPath(destDirectory), StringComparison.OrdinalIgnoreCase))
107-
{
108-
throw new InvalidOperationException("Attempt to extract file outside of the destination directory.");
109-
}
110-
111-
// Extract the file
112-
entry.ExtractToFile(destFileName, overwrite: true);
113-
}
97+
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory)
98+
{
99+
string destFileName = Path.GetFullPath(Path.Combine(destDirectory, entry.FullName));
100+
string fullDestDirPath = Path.GetFullPath(destDirectory + Path.DirectorySeparatorChar);
101+
if (!destFileName.StartsWith(fullDestDirPath)) {
102+
throw new System.InvalidOperationException("Entry is outside the target dir: " + destFileName);
103+
}
104+
entry.ExtractToFile(destFileName);
105+
}
114106
}
115107
}

0 commit comments

Comments
 (0)