usingSystem.Diagnostics;publicclassController{}publicclassExampleController:Controller{publicvoidExample(stringname,stringvalue){Processproc=newProcess();proc.StartInfo.FileName="path/to/executable";proc.StartInfo.EnvironmentVariables.Add(name,value);// Noncompliant: name is a variableproc.Start();}}
Compliant Code Examples
usingSystem.Diagnostics;usingSystem.Text.RegularExpressions;publicclassController{}publicclassExampleController:Controller{publicvoidExample(stringvalue){Processproc=newProcess();proc.StartInfo.FileName="path/to/executable";stringpattern="^*$";Matchm=Regex.Match(value,pattern);if(m.Success){// Name "ENV_VAR" is not in the sensitive list, so value being dynamic is ok here.proc.StartInfo.EnvironmentVariables.Add("ENV_VAR",value);}proc.Start();}}
シームレスな統合。 Datadog Code Security をお試しください
Datadog Code Security
このルールを試し、Datadog Code Security でコードを解析する
このルールの使用方法
1
2
rulesets:- csharp-security # Rules to enforce C# security.