问题
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" } );
回答1:
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 support@mongolab.com if you'd be interested in discussing the details.
回答2:
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.
回答3:
You have an API key for doing http request to your DB using their REST API. For example, if a user wants to log in I make a request with a GET method like this:
https://api.mongolab.com/api/1/databases/name_db/collections/users/put_your_params_like_username_and_pw?apiKey=xxxxxxxxx
And then you analyze the response to that request. It is not the most secure DB in the world but it is getting better.
If you want more info I talk about that in my blog: http://lolapriego.com/blog/?p=16
来源:https://stackoverflow.com/questions/12276146/how-does-mongolab-rest-api-authenticate