Я получаю проблему с обходом пути в snyk в моем коде ниже:
FileUtils.CopyFile(this.txtEnFileName.Text, fullEnPath, true, true);
У меня уже есть код над этой строкой для очистки входных данных, но при повторном сканировании я все равно получаю ту же проблему. Я думаю, Сник хочет, чтобы я изменил строку над ней. Я не уверен. Вот мой настоящий код:
// Sanitize inputs
string sanitizedSubDirName = Path.GetInvalidPathChars().Aggregate(subDirName, (current, c) => current.Replace(c.ToString(), string.Empty));
string sanitizedProduct = Path.GetInvalidFileNameChars().Aggregate(productList[count], (current, c) => current.Replace(c.ToString(), string.Empty));
string sanitizedRootFileName = Path.GetInvalidFileNameChars().Aggregate(rootFileName, (current, c) => current.Replace(c.ToString(), string. Empty));
// Combine paths safely
dstEnFileName = Path.Combine(sanitizedSubDirName, sanitizedProduct, sanitizedRootFileName + "EN.rtf");
dstFrFileName = Path.Combine(sanitizedSubDirName, sanitizedProduct, sanitizedRootFileName + "FR.rtf");
string fullEnPath = Path.GetFullPath(dstEnFileName);
string fullFrPath = Path.GetFullPath(dstFrFileName);
if (!fullEnPath.StartsWith(subDirName, StringComparison.OrdinalIgnoreCase) || !fullFrPath.StartsWith(subDirName, StringComparison.OrdinalIgnoreCase))
{
throw new UnauthorizedAccessException("Path traversal detected");
}
// Perform the file copy
FileUtils.CopyFile(this.txtEnFileName.Text, fullEnPath, true, true);
FileUtils.CopyFile(this.txtFrFileName.Text, fullFrPath, true, true);
Подробнее здесь: https://stackoverflow.com/questions/790 ... erse-issue