
cshekar641719 (Community Member) asked a question.
According to recommendation of CWE-78, my function below has been validated user input, but Veracode still reports that CWE-78 is available in that function.
private static void DisplayReport(string fileName)
{
var p = new Process();
var pi = new ProcessStartInfo {FileName = FilePathCleanser(fileName) };
p.StartInfo = pi;
p.Start();
}
private static string FilePathCleanser(string filename)
{
if (!string.IsNullOrEmpty(filename) && File.Exists(filename) && Path.GetFileNameWithoutExtension(filename).All(char.IsLetterOrDigit))
return filename;
return null;
}
.png)
Hi @cshekar641719 (Community Member),
Veracode Static Analysis is unable to verify the changes you have made sufficiently remove the risk from taking untrusted user input and executing it. The resolution for each instance is contextual to how the application processes the untrusted input, and so you will always be required to propose a mitigation. Such proposal should clearly state all the controls in place to mitigate the risk, such as from your example the following:
The mitigation should also detail any unaddressed, outstanding risk. I can see there is validation in place, but there are some questions I would have around this implementation:
Where possible it is always best to set the executable from a known and hard-coded list of allowed options that the application is in control of, rather than allow the user to specify the executable.
It is also a good idea to fully resolve the path using Path.GetFullPath() and verify the executable lives in a known and expected path, e.g. assert that the fully resolved path starts with "C:\App\Tools\".
Please also review this article which could assist you with the recommended validations required: https://community.veracode.com/s/article/how-do-i-fix-cwe-73-external-control-of-file-name-or-path-in-java.
I hope that helps.
Thanks,
Anthony Fielding
Thanks for sharing..