mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-13 00:31:28 +00:00
Prevent directory traversal attacks
This commit is contained in:
parent
b26d96bacd
commit
2cf2e6622a
3 changed files with 20 additions and 9 deletions
|
@ -56,6 +56,12 @@ public class ResourcesController : ControllerBase
|
|||
|
||||
string path = FileHelper.GetResourcePath(hash);
|
||||
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
string basePath = Path.GetFullPath(FileHelper.ResourcePath);
|
||||
|
||||
// Prevent directory traversal attacks
|
||||
if (!fullPath.StartsWith(basePath)) return this.BadRequest();
|
||||
|
||||
if (FileHelper.ResourceExists(hash)) return this.File(IOFile.OpenRead(path), "application/octet-stream");
|
||||
|
||||
return this.NotFound();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue