Do I need to sanitize user input before inserting in MongoDB (MongoDB+Node js combo)

前端 未结 2 910
清歌不尽
清歌不尽 2021-02-07 05:51

I\'m using MongoDB with NodeJS and am wondering if I need to sanitize data before inserting/updating database documents. Its hard to find definite answer and I\'m wondering if t

2条回答
  •  再見小時候
    2021-02-07 06:36

    Yes, you do. For more information check this out; https://www.npmjs.com/package/content-filter

    Also native escape() method might be used for to protect the database.

    Run the code snippet below to see the results.

    let a = "{$gt:25}"
    console.log(a)
    console.log(escape(a))

提交回复
热议问题