Nosql injection

1,472 views
Skip to first unread message

Jesse

unread,
Jun 9, 2011, 12:09:59 PM6/9/11
to Mongoose Node.JS ORM, san...@freeverse.com
I am in the process of building out a webapp on mongoose. Does the
query api... specifically find and find one automatically cleanse
query objects from nosql injection attacks? Is there any
"paramaterized" format that allows you to specify the query in a
format other than simply passing in query objects. My fear is that
doing something like

User.findOne({"name" : req.params.name, "password" :
req.params.password}, function(err, user){ return user;}); //possibly
open to nosql injection?

will allow users to injectoin something like

Usesr.findOne({"name" : "john", "password" : {$ne : 1}}, function(err,
user){ return user;}); //effectively selecting any john user with any
password (as long as it's not equal to 1)

If we need to cleans the query objects ourselves then I think it
should be made very apparent on the mongoose orm website and
everywhere in the docs. I think some people might be naive and think
that nosql solutions are somehow impervious to sql injection attacks.

see these docs:

http://erlend.oftedal.no/blog/?blogid=111

http://www.idontplaydarts.com/2010/07/mongodb-is-vulnerable-to-sql-injection-in-php-at-least/

Christopher Thorn

unread,
Jun 9, 2011, 3:27:45 PM6/9/11
to mongoo...@googlegroups.com
I think you are safe... mongoose won't try to parse JSON, but will
instead treat it as it should, as a string.

Aaron Heckmann

unread,
Jun 10, 2011, 9:25:14 AM6/10/11
to mongoo...@googlegroups.com
Yes, Mongoose casts values according to their schema which in this example means casting {$ne: 1} as a string before executing the query.

-- Aaron

Jesse Sanford

unread,
Jun 10, 2011, 11:10:42 AM6/10/11
to mongoo...@googlegroups.com
Fantastic. Thank you.
Reply all
Reply to author
Forward
0 new messages