Static code analysis issue of Unrestricted Upload of File

Jul 13 2018 5:32 AM
We done static code analysis using Kiuwan tool for our C# project and we are stuck at "UnrestrictedUpload of File with Dangerous Type" issue at "file.SaveAs(filePath)". We tried different ways to resolve it also the ways those are defined theoretically at
 
https://cwe.mitre.org/data/definitions/434.html . Any help from any of you is helpful.
  1. var directoryPath =Path.Combine(DocumentManagementRootDirectory , dbFile.ID.ToString());  
  2. Directory.CreateDirectory(directoryPath);  
  3. var path = Path.Combine(directoryPath , fName);  
  4. file.SaveAs(path);  
This is the code where we get this issue. We are not getting how to fix this one. This really sucks. May there is simple fix for this but we are not getting that. Any help from all of you is appriciable.
 
Regards,