Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb security in node.js

For say a MySQL database there are known security issues. How does this apply to a NoSQL db? e.g. Injections, xss etc. What are the security measurement you have to take when using a NoSQL db? Specifically regarding MongoDB (with node-mongodb-native) and Node.js (using Express)

And if so, are there any modules for Node/Express that helps in preventing this?

like image 430
georgesamper Avatar asked Jun 10 '12 14:06

georgesamper


People also ask

How MongoDB is secure?

TLS/SSL Encryption Network encryption is available with MongoDB. This allows you to protect your database and communications through an industry-standard encryption methodology. TLS and SSL are supported by the x. 509 certificates, which clients can use to authenticate their identities.

Is MongoDB good for node JS?

The MongoDB Node. js driver makes using MongoDB with Node. js a seamless experience. The driver automatically maps JavaScript objects to BSON documents, meaning that developers can easily work with their data.

Is Node JS good for security?

The Node. js platform is inherently secure, but because it uses third-party open source packages through its package management system (npm), it is vulnerable to cyber attacks. Companies must implement the best practices like those outlined in this article to maintain the security of Node. js.

What is JWT in MongoDB?

Overview. The Custom JWT authentication provider allows users to authenticate with an authentication system that is independent from Atlas App Services. The external system must return a signed JSON Web Token that contains a unique ID value for the authenticated user.


1 Answers

There is specific issue for NodeJS, MongoDB (and some others NoSQL databases that heavily use javascript): serverside javascript injection. Look here and here (pdf) for details. It is more like SQL injection than XSS.

Shortly, that is when attacker sends javascript to your nodejs or mongodb when you're expecting just JSON. So theoretically bad guy can bring your service down (DOS), access your data and even filesystem.

To prevent such attacks you have to:

  1. Avoid creating “ad-hoc” JavaScript commands by concatenating script with user input.
  2. Validate user input used in SSJS commands with regular expressions.
  3. Avoid use of the JavaScript eval command. In particular, when parsing JSON input, use a safer alternative such as JSON.parse.
like image 129
om-nom-nom Avatar answered Nov 15 '22 23:11

om-nom-nom