Current code in my project is shown below and Veracode reports there is an OS command injection
filename = Regex.Replace(filename, "[^a-zA-Z0-9_]", "_") & ".svg"
ProcessStartInfo startInfo = default(ProcessStartInfo);
Process pStart = new Process();
startInfo = new ProcessStartInfo(myExecutedFilePath, "\"" + filename + "\" --export-pdf=\"" + filename + "\""); **//OS command injection raises at this line**
pStart.StartInfo = startInfo;
pStart.Start();
pStart.WaitForExit();
So, I research the solution to solve this issue from OWASP and Roslyn Security Guard.
- OWASP post: https://www.owasp.org/index.php/OS_Command_Injection_Defense_Cheat_Sheet
- Roslyn Security Guard post: https://dotnet-security-guard.github.io/SG0001.htm
And here is my code after modifying based on that posts.
filename = Regex.Replace(filename, "[^a-zA-Z0-9_]", "_") & ".svg"
ProcessStartInfo startInfo = default(ProcessStartInfo);
Process pStart = new Process();
startInfo = new ProcessStartInfo();
startInfo.FileName = myExecutedFilePath;
startInfo.Arguments = "\"" + filename + "\" --export-pdf=\"" + filename + "\""; **//Veracode still reports the issue at this line**
pStart.StartInfo = startInfo;
pStart.Start();
pStart.WaitForExit();
BUT, Veracode still reports OS command injection.
So my concerns here are:
Did I apply the correct solution to solve OS command injection in this case?
Or, Should I propose mitigation for it?