Skip to content

Commit 7f92756

Browse files
authored
Merge pull request #247 from 0xLanks/fix-security-issues
Fixed security issues
2 parents 11b9f17 + 035bc37 commit 7f92756

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

BlogEngine/BlogEngine.Core/Services/Syndication/BlogML/BlogReader.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ public string XmlData
5353
/// <summary>
5454
/// Gets an XmlReader that converts BlogML data saved as string into XML stream
5555
/// </summary>
56-
private XmlTextReader XmlReader
56+
private XmlReader XmlReader
5757
{
5858
get
5959
{
6060
var byteArray = Encoding.UTF8.GetBytes(this.xmlData);
6161
var stream = new MemoryStream(byteArray);
62-
return new XmlTextReader(stream);
62+
XmlReaderSettings settings = new XmlReaderSettings();
63+
settings.XmlResolver = null;
64+
return XmlReader.Create(stream, settings);
6365
}
6466
}
6567

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

BlogEngine/BlogEngine.NET/Global.asax

+13
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@
1212
{
1313
BlogEngineConfig.SetCulture(sender, e);
1414
}
15+
16+
protected void Application_PreSendRequestHeaders ()
17+
{
18+
var httpContext = HttpContext.Current;
19+
if (httpContext != null) {
20+
var cookieValueSuffix = "; SameSite=Strict";
21+
var cookies = httpContext.Response.Cookies;
22+
for (var i = 0; i < cookies.Count; i++)
23+
{
24+
var cookie = cookies[i]; cookie.Value += cookieValueSuffix;
25+
}
26+
}
27+
}
1528
</script>

0 commit comments

Comments
 (0)