OS command injection (ARCH316)
Ce contenu n’est pas encore disponible dans votre langue.
Key dotnet.security.os-command-injection · Severity error · Category security · CWE CWE-78
Concatenating user input into a shell command line lets an attacker inject extra commands. Pass arguments separately without a shell.
Incorrect
Section titled “Incorrect”Process.Start("cmd.exe", "/c ping " + userHost);Correct
Section titled “Correct”var psi = new ProcessStartInfo("ping") { UseShellExecute = false };psi.ArgumentList.Add(userHost);Process.Start(psi);Pass arguments via ArgumentList, set UseShellExecute = false, and never concatenate input into a shell command string.