Mongoose.JS countDocuments()是否验证过滤器?

编程入门 行业动态 更新时间:2024-10-12 20:19:57

Mongoose.JS countDocuments()是否验证<a href=https://www.elefans.com/category/jswz/34/1771166.html style=过滤器?"/>

Mongoose.JS countDocuments()是否验证过滤器?

MongooseJS函数Model.countDocuments()是否验证所使用的过滤器?还是受到不安全输入的注入攻击?

例如,

var mongoose = require('mongoose')

var TestSchema = new mongoose.Schema({
    firstname: String,
    lastname: String,
    job_title: String
})

var Test = mongoose.model('Test', TestSchema)

Test.countDocuments({ job_title: request.body.manager_search })
    .then((result) => { console.log("result: ", result) })
    .catch((err) => { console.log("Error counting documents: ", err) })

此代码是引入注入矢量,还是request.body.manager_search将通过此函数转换为字符串?

回答如下:

否,它不会验证,也不会强制转换为String

猫鼬调用本机MongoDB收集方法countDocuments(query, options)

如果query包含注入向量(例如job_title: {'$ne':''},see restrictions),MongoDB 将不会阻止应用程序中的注入

示例:

{ job_title:  'foo'  }
result:  2

{ job_title:  { '$ne': '' }  }
result:  3

解决方案:

棘手的解决方案:{ job_title: {$in:[request.body.manager_search] } }棘手的解决方案2:{ job_title: request.body.manager_search + "" }Mongo消毒:https://www.npmjs/package/mongo-sanitize

更多推荐

Mongoose.JS countDocuments()是否验证过滤器?

本文发布于:2024-05-06 23:45:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   Mongoose   JS   countDocuments

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!