首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SonarQube漏洞

SonarQube漏洞
EN

Stack Overflow用户
提问于 2021-03-07 02:29:07
回答 1查看 94关注 0票数 0

我刚开始使用SonarQube,我正在尝试修复一些漏洞,但不确定如何修复。我还附上了显示sonarQube问题的图像。我的直觉告诉我,我需要以某种方式验证selectedFileName参数。非常感谢您的想法和想法。

代码如下:

代码语言:javascript
复制
[HttpGet("[action]/{selectedFileName}/{selectedTruckModel}/{selectedTravelTimeSettingName}/{selectedCorneringSettingId}/{selectedImportTemplateSettingId}/{selectedPropertiesName}")]
public IEnumerable<RPMTravelTimeTest> CalculateTravelTimeFromSegmentFile(string selectedFileName, string selectedTruckModel, string selectedTravelTimeSettingName, string selectedCorneringSettingId, string selectedImportTemplateSettingId,string selectedPropertiesName)
{
        var travelTimeTestList = new RPMTravelTimeTestCollection();
        travelTimeTestList.LoadTravelTimeTestBySegmentFile(_isHaaSProduction,
                                                           config.Value.StandardHaulageConnectString,
                                                           selectedTruckModel,
                                                           selectedTravelTimeSettingName,
                                                           selectedCorneringSettingId,
                                                           selectedImportTemplateSettingId,
                                                           selectedFileName,
                                                           selectedPropertiesName);

    return travelTimeTestList;
}

EN

回答 1

Stack Overflow用户

发布于 2021-03-20 15:01:53

我会尽我所能回答这个问题。

这里的SonarScanner标识您正在创建一个类RPMTravelTimeTestCollection的实例,并使用LoadTravelTimeTestBySegmentFile方法使用用户输入数据直接构建该对象。SonarScanner确定并决定安全敏感的实际问题是selectedFileName字符串变量,该变量由您声明的HTTP GET方法的调用者提供。

我不知道你是如何处理selectedFilename用户输入的,但有可能你不能避免路径遍历漏洞,更多信息在这里:https://owasp.org/www-community/attacks/Path_Traversal

您可以在LoadTravelTimeTestBySegmentFile方法中实现输入验证,该方法验证变量selectedFilename没有被提供给路径遍历字符或任意文件扩展名,但为了避免使用正则表达式或类似技术的错误验证实现,我将使用如下白名单实现:

代码语言:javascript
复制
public bool ValidateFileName(string fileName, string destDirectory)
{
    // destDirectory could be "C:/Users/example/App_Data/traveltimesfolder/"
    // fileName could be traveltimes.csv

    string destFileName = Path.GetFullPath(System.IO.Path.Combine(destDirectory, fileName));
    string fullDestDirPath = Path.GetFullPath(destDirectory + Path.DirectorySeparatorChar);

    return destFileName.StartsWith(fullDestDirPath, StringComparison.Ordinal);
}

如果用户尝试使用路径遍历字符访问您使用destDirectory参数指定的所提供方法之外的文件夹,则上述代码将返回false。您应该通过添加文件扩展名检查和其他类型的规则来执行安全文件读取来丰富上面的验证。

您甚至可以继续编写一些单元测试,使用从有效负载列表馈送的恶意输入数据进行测试,您可以在此处找到各种路径遍历有效负载:https://github.com/danielmiessler/SecLists

如果该漏洞仍然存在于SonarQube web界面中,则通过web界面将该漏洞设置为已修复,并在注释部分中解释您采取了哪种类型的安全措施来保护变量的处理。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66509243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档