Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Mongolab REST API authenticate

The REST API for Mongolab is cool. I can use that for analytics in my website directly using the following javascript, provided on Mongolab's support page. Only if I can understand how the authentication actually works. The API key mentioned in the URL could be easily copied by anyone who'd view the html source. The Mongolab control panel does not offer any registration for my website that'd assure me that the api key will be validated only if coming from my domain. How does this authentication work?

$.ajax( { url: "https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=myAPIKey",
          data: JSON.stringify( { "x" : 1 } ),
          type: "POST",
          contentType: "application/json" } );
like image 582
brayne Avatar asked Sep 05 '12 07:09

brayne


People also ask

What kind of authentication is supported in MongoDB?

MongoDB supports x. 509 certificate authentication for client authentication and internal authentication of the members of replica sets and sharded clusters. x. 509 certificate authentication requires a secure TLS/SSL connection.


2 Answers

Excellent observation, and great question.

Currently, all API keys have read and write access to the databases associated with the user's account, and any agent possessing an API key can successfully issue any such request.

As you observe, this very basic pass key is not designed with any kind of fine-grained security in mind.

However, we're working on a batch of new REST API security features aimed at precisely that.

Contact us at [email protected] if you'd be interested in discussing the details.

like image 106
dampier Avatar answered Sep 22 '22 14:09

dampier


I'd like to use MongoLab service for my first AngularJs app with MongoDB, but MongoLab is not ready for production with a web app that wants access from the front end to the MongoDB.

It's very easy to get the API key in the browsers network traffic (see screenshot below, the apiKey is in plain text there) and then any one can have full access to the DB. So messing around with the MongoDB would be no problem.

I haven't found a workaround for MongoLab yet. At the moment, I think I will use another service like https://www.dreamfactory.com/

I haven't tried it in detail yet but it looks great for an AngularApp with MongoDB and I need to check how they implemented the security of the api. On the first look, it looks like it is working with session tokens to secure the requests to the database.

Screenshot network traffic MongoLab credentials

like image 34
AWolf Avatar answered Sep 21 '22 14:09

AWolf