Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  53] [ 5]  / answers: 1 / hits: 28395  / 12 Years ago, sun, november 18, 2012, 12:00:00

How can I prevent JavaScript NoSQL injections into MongoDB?



I am working on a Node.js application and I am passing req.body, which is a json object, into the mongoose model's save function. I thought there were safeguards behind the scenes, but this doesn't appear to be the case.


More From » node.js

 Answers
113

Note
My answer is incorrect. Please refer to other answers.



--



As a client program assembles a query in MongoDB, it builds a BSON object,
not a string. Thus traditional SQL injection attacks are not a problem.



For details follow the documentation



UPDATE



Avoid expression like eval which can execute arbitrary JS. If you are taking input from user and running eval like expressions without cleaning the input you can screw up. As pointed by JoBu1324, operations like where, mapReduce and group permit to execute JS expressions directly.


[#81933] Friday, November 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradleymoisesy

Total Points: 121
Total Questions: 105
Total Answers: 95

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
bradleymoisesy questions
Wed, Dec 22, 21, 00:00, 2 Years ago
Tue, Jun 1, 21, 00:00, 3 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
Thu, Jan 16, 20, 00:00, 4 Years ago
;