
NGupta728957 (Community Member) asked a question.
We are facing issue in resolving Command or Argument Injection Flaw [CWE ID 78].
In above code in line no 848 veracode is throwing issue for untrusted input because linktext we are passing in the function contains dynamic values.
I tried to validate the dynamic input using uri libraries and Regex pattern. But that doesn't seems to be helping.
Validation using URI library :
Validation using Regex patter :
Need guidance on how to resolve these flaws.
.png)
Hi @NGupta728957 (Community Member),
It seems to me that you are trying to open a web browser and navigate to the provided URL. the only code change Veracode Static Analysis would automatically detect here is validating the untrusted parts of the URL against an allow-list. The following Knowledge Article describes how to implement an allow-list in a way Veracode Static Analysis can detect: https://community.veracode.com/s/article/Using-an-Allow-list-in-a-Way-Static-Analysis-can-Detect.
In any other case, I would recommend the following:
For the last point, it might be a good idea to explicitly specify that `explorer.exe` may be used (this should work for your use case). The resulting code would be something like this: `Process.Start("explorer.exe", url);`.
However, even then there is a potential risk of a malicious user attempting to put a malicious binary (which they would also name "explorer.exe") in a directory higher up the PATH. This would then potentially be executed instead of the intended `explorer.exe`. The safest way to deal with this is probably something like this:
String windir = Environment.GetEnvironmentVariable("windir");
String explorer = $"{windir}\\explorer.exe";
System.Diagnostics.Process.Start(explorer, url);
This uses the `windir` variable (has the value `%SystemRoot%` which usually points to `C:\Windows`, where `explorer.exe` is located). The remaining risk here would be that an attacker with admin privileges might be able to change the environment variable `windir` to another path with their own malicious `explorer.exe` inside. But that risk is probably very acceptable.
Please note that you would have to propose a mitigation by design for this and discuss it with your organization's Security Team. For more information on this, please refer to https://docs.veracode.com/r/improve_mitigation.
Thank you,
Florian Walter