Skip to content

Commit

Permalink
Resolved security issue in FTP service provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
sivakumars3442 committed Dec 20, 2023
1 parent 88aac40 commit 0c9218e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Models/FTPFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,10 @@ protected void UploadFile(IFormFile file, string fileName)
protected FileStreamResult DownloadFile(string fullPath, string folderPath)
{
string tempPath = this.GetTempFilePath(fullPath, folderPath);
if (Path.GetFullPath(tempPath) != Path.GetDirectoryName(tempPath) + Path.DirectorySeparatorChar + Path.GetFileName(tempPath))
{
throw new UnauthorizedAccessException("Access denied for Directory-traversal");
}
FileStream fileStreamInput = new FileStream(tempPath, FileMode.Open, FileAccess.Read);
FileStreamResult fileStreamResult = new FileStreamResult(fileStreamInput, "APPLICATION/octet-stream");
return fileStreamResult;
Expand All @@ -1200,6 +1204,10 @@ protected void CopyFile(string fileName, string tempPath)
{
FtpWebResponse response = this.CreateResponse(fileName, WebRequestMethods.Ftp.DownloadFile);
byte[] buffer = this.ConvertByte(response.GetResponseStream());
if (Path.GetFullPath(tempPath) != Path.GetDirectoryName(tempPath) + Path.DirectorySeparatorChar + Path.GetFileName(tempPath))
{
throw new UnauthorizedAccessException("Access denied for Directory-traversal");
}
using (Stream file = File.OpenWrite(tempPath))
{
file.Write(buffer, 0, buffer.Length);
Expand Down

0 comments on commit 0c9218e

Please sign in to comment.