|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Security; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Domain.Services; |
|
|
|
using Volo.Abp.IO; |
|
|
|
@ -15,7 +16,11 @@ namespace Volo.Docs.FileSystem.Documents |
|
|
|
|
|
|
|
public async Task<Document> GetDocument(Project project, string documentName, string version) |
|
|
|
{ |
|
|
|
var path = Path.Combine(project.GetFileSystemPath(), documentName); |
|
|
|
var projectFolder = project.GetFileSystemPath(); |
|
|
|
var path = Path.Combine(projectFolder, documentName); |
|
|
|
|
|
|
|
CheckDirectorySecurity(projectFolder, path); |
|
|
|
|
|
|
|
var content = await FileHelper.ReadAllTextAsync(path); |
|
|
|
var localDirectory = ""; |
|
|
|
|
|
|
|
@ -43,8 +48,23 @@ namespace Volo.Docs.FileSystem.Documents |
|
|
|
|
|
|
|
public async Task<DocumentResource> GetResource(Project project, string resourceName, string version) |
|
|
|
{ |
|
|
|
var path = Path.Combine(project.GetFileSystemPath(), resourceName); |
|
|
|
var projectFolder = project.GetFileSystemPath(); |
|
|
|
var path = Path.Combine(projectFolder, resourceName); |
|
|
|
|
|
|
|
if (!DirectoryHelper.IsSubDirectoryOf(projectFolder, path)) |
|
|
|
{ |
|
|
|
throw new SecurityException("Can not get a resource file out of the project folder!"); |
|
|
|
} |
|
|
|
|
|
|
|
return new DocumentResource(await FileHelper.ReadAllBytesAsync(path)); |
|
|
|
} |
|
|
|
|
|
|
|
private static void CheckDirectorySecurity(string projectFolder, string path) |
|
|
|
{ |
|
|
|
if (!DirectoryHelper.IsSubDirectoryOf(projectFolder, path)) |
|
|
|
{ |
|
|
|
throw new SecurityException("Can not get a resource file out of the project folder!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|