Skip to content

Commit 2b9d135

Browse files
authored
Merge pull request #14 from bmoussaud/fix-security-issue
fix #12: Security Issue
2 parents fc057fa + 4c27d8a commit 2b9d135

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ public async Task<IActionResult> OnPostAnalyzeMessagesAsync()
9292
return RedirectToPage();
9393
}
9494

95-
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory)
95+
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory)
9696
{
97-
string destFileName = Path.Combine(destDirectory, entry.FullName);
97+
string destFileName = Path.GetFullPath(Path.Combine(destDirectory, entry.FullName));
98+
string fullDestDirPath = Path.GetFullPath(destDirectory + Path.DirectorySeparatorChar);
99+
if (!destFileName.StartsWith(fullDestDirPath)) {
100+
throw new System.InvalidOperationException("Entry is outside the target dir: " + destFileName);
101+
}
98102
entry.ExtractToFile(destFileName);
99103
}
100104
}

0 commit comments

Comments
 (0)