I have this code that stores file to server:
function void StoreFile(string inputFileName) {
...
var extension = Path.GetExtension(inputFileName);
if(extension == ".csv") {
var fileName = string.Format("{0}_{1}{2}", Session.SessionID, new Guid(), extension);
var dataFileServerPath = _documentService.getPath(fileName, UserProfile.UserName, UserProfile.SourceID);
if(!string.IsNullOrEmpty(dataFileServerPath)) {
try {
using(FileStream dataFile = new FileStream(dataFileServerPath, FileMode.Create)) { .... }
}
cathc(Exception e) { ... }
}
}
else {
throw new NotSupportedFormatError();
}
}
Aftrer Veracode analyze I get Directory Traverse Issue on line FileStream dataFile = new FileStream(dataFileServerPath, FileMode.Create)
Why am I getting this issue there, I've checked if file extension is valid for my case and passed that value in fileName. Is this security issues and how to solve this issue?
_documentService.getPath
just appends path from web.config and filename for specific user, it's not related to user input.