0

i know this is a question that has been asked many time. but im still concerned about best practice when trying to develop secure code in meteor.

i know you can prevent the client from being able to access the database with the command:

meteor remove insecure

my code currently adds, retrieves records by using Meteor.methods() so although the client is not able to insert data into a collection, it can use the Meteor.method() function. im concerned about holding the login details in the database because would this not mean that the client can use the Meteor.method() function to add/get/remove data from the database.

the client being able to call the Meteor.methods() function seems to still keep the same risk doesn't it? or have i coded me work wrong?

if it help, here is a run down of what my work is doing:

  1. application loads
  2. client calls to get username and password from database
  3. client sends login details to external server (over https) to initiate socket.io connection.

step 2 is the risk because it seems to allow the client to get the login details. once it has this, it uses the socket.io.js library and the api to my webservice to login. so meteor remove insecure doesnt seem to have secured it because get methods are still available in the Meteor.methods()?

being able to use these functions are quite crucial to retrieving data from the database, is there a way around this? what would be best practice for communicating to the database without exposing private data to the client?

1
  • You ask too many questions. Please narrow down your post to a couple, localized, precise questions. Your issue is also unclear (I still hardly have any idea what's happening in your app). Please edit your post.
    – Kyll
    Jul 1, 2015 at 12:50

2 Answers 2

0

Meteor's insecure package is just a tool provided by MDG to quickly prototype apps. It is not meant to be runned in a production app and some people think is a best practise to remove it all together from the start.

After you remove this package, if you want to interact with the database on the client using mini-mongo you must create the appropiate allow and deny rules on the collection. Here is the link for the Meteor documentation on this topic. The other way to interact with the database, is as you said, using Meteor.methods().

Meteor methods calls don't trigger allow or deny rules, since they are runned on the server. You must hardwire all the security measures you need on the Meteor Call by yourself. So it can be a security problem if you don't take the time to secure the call.

Regarding authenticating your clients I would suggest you take a look at Meteor's Accounts package. For example you can add this two packages for basic username/password authentication:

meteor add accounts-base accounts-passwords

Then you can just use the methods detailed on the Meteor Documentation.

I hope this helps.

0

Login

If you are using accounts-password, you can check the source here to see details of how it works. But here's a rough overview of it. When you call Meteor.loginWithPassword, the password is hashed client-side. Then a method is called with the parameters. The password is then salted and checked against the database server-side. If it matches, the client gets logged in. The client then subscribes to their own user data (Meteor.user()). The server only publishes their data. So everyone else's data is save.

Methods

A method executes code server-side. So they are generally secure. But you can of course write insecure methods. Just know, that you can't trust the parameters passed by the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.