在我按照 OWAPS 和 Roslyn Security Guard 的建议应用解决方案后,Veracode 仍然报告操作系统命令注入问题

2024-03-19

我的项目中的当前代码如下所示,Veracode 报告存在操作系统命令注入

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();

因此,我从 OWASP 和 Roslyn Security Guard 那里研究了解决此问题的解决方案。

  • OWASP 帖子:https://www.owasp.org/index.php/OS_Command_Injection_Defense_Cheat_Sheet https://www.owasp.org/index.php/OS_Command_Injection_Defense_Cheat_Sheet
  • 罗斯林保安岗:https://dotnet-security-guard.github.io/SG0001.htm https://dotnet-security-guard.github.io/SG0001.htm

这是我根据该帖子修改后的代码。

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();

但是,Veracode 仍然报告操作系统命令注入。

所以我的担忧是:

  1. 在这种情况下,我是否应用了正确的解决方案来解决操作系统命令注入?

  2. 或者,我应该建议缓解措施吗?


我已收到 Veracode 的答复。

“你是对的,在 ProcessStartInfo 对象中分离文件路径和参数是一个好的开始,并且验证文件名仅包含字母数字字符也应该有所帮助。

静态引擎仍然将此报告为缺陷的可能原因是 Veracode 无法识别 CWE 78 的 .NET 的任何清理函数。因此,任何时候我们看到用户输入被传递到代表命令的函数“我们将标记为 CWE 78。我们也不评估正则表达式字符串的准确性/有效性,因此即使正则表达式完全准确,我们仍然会标记该缺陷。

两个建议:

  1. 如果您想要我们的其中一项服务,请考虑安排一次咨询 应用程序安全顾问帮助验证您的更改在上下文中是否正确。
  2. 一旦您对修复感到 100% 满意 解决了该缺陷,我建议在缓解措施中记录这一点。 ”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在我按照 OWAPS 和 Roslyn Security Guard 的建议应用解决方案后,Veracode 仍然报告操作系统命令注入问题 的相关文章

随机推荐