【问题标题】:Improper Neutralization of Special Elements in Data Query Logic for Mongoose Create in VeracodeVeracode 中 Mongoose Create 的数据查询逻辑中特殊元素的中和不当
【发布时间】:2020-09-22 11:25:02
【问题描述】:

我正在使用猫鼬创建功能来添加到我的收藏中。我正在从请求正文中获取数据并将其传递以创建这样的函数 -

const someVariable = req.body;

await userModelName.create(someVariable);

veracode 上,它显示此语句的数据查询逻辑中特殊元素的不正确中和 - await userModelName.create(someVariable);

有什么方法可以修改此代码以从 veracode 中删除此警报?

【问题讨论】:

    标签: mongodb mongoose veracode


    【解决方案1】:

    您需要使用 req.body 执行清理、验证或编码。盲目接受可能受到污染或来自不受信任的来源的输入是有风险的。

    我假设您期望以 json 形式输入,因此请尝试使用 js-string-escape 库转义 req.body:

    var jsescape = require('js-string-escape');
    const someVariable = jsescape(req.body);
    await userModelName.create(someVariable);
    

    现在 Veracode 可能无法识别此第三方编码库,并且仍然无法扫描。您必须将此作为mitigation 步骤提交给您的安全团队。

    如果您需要特定类型的数据,另一种选择是使用 Mongoose 的 Validation 功能:

    const schema = new Schema({
      name: {
        type: String,
        required: true
      }
    });
    
    const someVariable = escape(req.body);
    await userModelName.create(someVariable, schema);
    

    同样,Veracode 可能也无法识别这一点,但这些是安全编码最佳实践。

    【讨论】:

    • 是的,req.body 有 json 格式的数据。那么在 mongoose create() 函数中,数据将被转换回原始形式?
    • 在意识到转义方法的输出不是您所期望的结果后,我收回了原来的答案并修改了我的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    • 2014-12-25
    • 2014-05-21
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多