Insecure Use of Dangerous Function
This vulnerability category covers the following issues:
Command Injection
Why is this important?
Dotnet , like any other programming language, has dangerous functions. If these functions are not used properly, it can have a catastrophic impact on your app.
Attacker controlled input that is processed by these functions, can lead to attackers getting full access to your production environment.
Check out this video for a high-level explanation:
If possible, it's always best to avoid using these functions with user input. However, if they have to be used in conjunction with user input, then read below to find out how to fix this issue in your code.
References:
Fixing Insecure Use of Dangerous Function
Option A: Use the dangerous function securely
- Go through the issues that GuardRails identified in the PR.
- Locate the dangerous function. For example:
var p = new Process();
p.StartInfo.FileName = "exportLegacy.exe";
p.StartInfo.Arguments = " -user " + input + " -role user";
p.Start();
- Apply input filtering like shown below
Regex rgx = new Regex(@"^[a-zA-Z0-9]+$");
if(rgx.IsMatch(input))
{
var p = new Process();
p.StartInfo.FileName = "exportLegacy.exe";
p.StartInfo.Arguments = " -user " + input + " -role user";
p.Start();
}
- Test it and ensure the functionality works as expected
- Ship it 🚢 and relax 🌴