Skip to content

Commit 035bc37

Browse files
0xLanks0xLanks
0xLanks
authored and
0xLanks
committed
Fixed authorization controls on controller actions and added path sanitization preventing path traversal
1 parent 16343de commit 035bc37

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

BlogEngine/BlogEngine.NET/AppCode/Api/FileManagerController.cs

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using BlogEngine.Core.Data.Contracts;
1+
using BlogEngine.Core;
2+
using BlogEngine.Core.Data.Contracts;
23
using BlogEngine.Core.FileSystem;
34
using BlogEngine.Core.Providers;
45
using System;
@@ -24,6 +25,11 @@ public IEnumerable<FileInstance> Get(int take = 10, int skip = 0, string path =
2425
[HttpPut]
2526
public HttpResponseMessage ProcessChecked([FromBody]List<FileInstance> items)
2627
{
28+
if (!Security.IsAdministrator)
29+
{
30+
throw new UnauthorizedAccessException();
31+
}
32+
2733
if (items == null || items.Count == 0)
2834
throw new HttpResponseException(HttpStatusCode.ExpectationFailed);
2935

@@ -36,10 +42,10 @@ public HttpResponseMessage ProcessChecked([FromBody]List<FileInstance> items)
3642
if (item.IsChecked)
3743
{
3844
if(item.FileType == FileType.File || item.FileType == FileType.Image)
39-
BlogService.DeleteFile(item.FullPath);
45+
BlogService.DeleteFile(Extensions.SanitizePath(item.FullPath));
4046

4147
if (item.FileType == FileType.Directory)
42-
BlogService.DeleteDirectory(item.FullPath);
48+
BlogService.DeleteDirectory(Extensions.SanitizePath(item.FullPath));
4349
}
4450
}
4551
}
@@ -49,7 +55,11 @@ public HttpResponseMessage ProcessChecked([FromBody]List<FileInstance> items)
4955
[HttpPut]
5056
public HttpResponseMessage AddFolder(FileInstance folder)
5157
{
52-
BlogService.CreateDirectory(folder.FullPath + "/" + folder.Name);
58+
if (!Security.IsAdministrator)
59+
{
60+
throw new UnauthorizedAccessException();
61+
}
62+
BlogService.CreateDirectory(Extensions.SanitizePath(folder.FullPath) + "/" + Extensions.SanitizePath(folder.Name));
5363
return Request.CreateResponse(HttpStatusCode.OK);
5464
}
5565

0 commit comments

Comments
 (0)