
GBhatnagar521131 (Community Member) asked a question.
Hello,
I ran Veracode scan on my Windows applications and its dlls.
One of the vulnerabilities reported was:
Directory Traversal(1 flaw)
Associated Flaws by CWE ID: External Control of File Name or Path (CWE ID 73)(1 flaw)
It was on the following line in BOLD text.
How do I rectify it.
string GoogleSecID = System.Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIAL_PATH", EnvironmentVariableTarget.Machine);
string appconfigValue = System.Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_SECRET", EnvironmentVariableTarget.Machine);
GoogleSecID = GoogleSecID.Replace(".p12", "");
string extension = "p12";
string filepath = ValidateFileNamePath(AppDomain.CurrentDomain.BaseDirectory, GoogleSecID, extension);
certificate = new X509Certificate2(filepath, appconfigValue, X509KeyStorageFlags.Exportable);
...
...
...
...
[FilePathCleanser]
private string ValidateFileNamePath(string basePath, string path, string extension)
{
string[] allowedExtensions = new String[] { "p12" };
//string extension = ".p12"; // Default extension
foreach(string allowedExtension in allowedExtensions)
{
if (allowedExtension.Contains(Path.GetExtension(path)))
{
extension = allowedExtension;
}
}
path = basePath + path + "." + extension;
string absolutePath = Path.GetFullPath(path);
if (!absolutePath.StartsWith(basePath))
{
throw new Exception("Potential path traversal. Path: " + path + ", AnsolutePath: " + absolutePath);
}
return absolutePath;
}
Thanks,
Gagan
.png)
Hi @GBhatnagar521131 (Community Member) ,
We see that you are implementing a custom cleanser function to address CWE 73 findings.
Please note that custom cleanser annotation/attribute is only in effect and recognized by SAST scanning if it is enabled by Admin.
Please refer to this link :
https://docs.veracode.com/r/c_cleanser_admin
Please check with your organization's AppSec team to confirm the enablement of this feature.
If your AppSec team does not want to enable this setting, you can consider manually raising Mitigation by design proposal for these findings.
If you still have questions I would recommend you schedule a consultation call to discuss.
You can check out this knowledge article (https://community.veracode.com/s/article/How-to-schedule-a-consultation-call) on how to schedule a consultation call with us.
Regards,
Kashif.