Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions FileShares/src/FileSharesWeb/Controllers/FilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,17 @@ public ActionResult List()
[HttpDelete]
public JsonResult Delete(string fileToDelete)
{
string actualFileName = HttpUtility.UrlDecode(fileToDelete);
SystemFile.Delete(actualFileName);
return Json($"Successfully deleted {actualFileName}");
string fileName = HttpUtility.UrlDecode(fileToDelete);
string shareRoot = Path.GetFullPath(fileShareConfiguration.Location);
string filePath = Path.GetFullPath(Path.Combine(shareRoot, fileName));

if (!filePath.StartsWith(shareRoot + '\\', StringComparison.OrdinalIgnoreCase) &&
!filePath.StartsWith(shareRoot + '/', StringComparison.OrdinalIgnoreCase))
{
throw new UnauthorizedAccessException("Deleting files outside the share root is not permitted.");
Comment thread
TimHess marked this conversation as resolved.
}

SystemFile.Delete(filePath);
return Json($"Successfully deleted {fileName}");
}
}