Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoDB injection

is there a common pattern in Java to avoid mongoDB injection attacks?

Thanks

like image 487
Mark Avatar asked Nov 12 '10 16:11

Mark


2 Answers

Use one of the supported drivers. Don't deserialize strings as JSON and pass them as queries, e.g. dont' do this (in Ruby):

collection.send(query_type, JSON.parse(parameters))

where query_type and parameters are strings coming from a form. You would have to be criminally stupid to do this though.

Since there's no query language as such there's not the same room for injection. Part of the reason that SQL injection attacks are possible is that the action to take (SELECT, UPDATE, DELETE, etc.) is part of the query string. MongoDB, and many other newer databases, don't work like that, instead the action is a part of the API. Where SQL drivers only have query and in some cases exec, MongoDB has find, update, insert and remove.

like image 173
Theo Avatar answered Oct 11 '22 14:10

Theo


You can build MongoDB querys with Javascript in the where clause and here injection can happen. Here explanation how to prevent this: https://docs.mongodb.com/manual/faq/fundamentals/#how-does-mongodb-address-sql-or-query-injection

like image 26
TTT Avatar answered Oct 11 '22 13:10

TTT