I am working on a Meteor application that uses Iron Router. We have a login page in our application. Even when the user is not logged in, if I call the below code on developer console as un-authenticated user:
Router.routes
It gives all the routes and the respective paths. Is there a way to disable access to these paths or do I need to push these end points in the server code ?
Everything you define on the client is visible on the client. So is all the routes definitions and routes logic, too. In production code this will be obfuscated but it's still there.
If you are concerned, that clients can read your routes, then you should be more concerned about the fact that it concerns you. Sounds a bit confusing but the point is: you should double check each data published to client via publications or manipulated / created via methods on server. If your backend is robust and secured as much as possible (100% will never be possible), then you don't need to care, if clients can see which routes exist and get access to them.
An example:
Bob found the route
/adminand disabled the router's triggers to redirect him if he is not Admin.Now Bob could see all data, that Admins can see. To prevent this, you may check in the
publicationif Bob has the role 'admin' on don't publish to him if he's not admin.Ada also found this way to the Admin panel and wants to create a new user. Because your server method for creating new users is a
ValidatedMedthodthat checks if Ava has the 'admin' role it will fail to create a new user, because Ava is not an admin.Conclusion:
Preventing access on the client side is just UI Magic bot not secure at all. Simple tweaks, however on the server side will help you to sleep better.
More help:
A good way to get started is to read the Meteor Security Guide:
https://guide.meteor.com/security.html
There is also at the end a security checklist, which I just cite for completeness and SEO reasons here:
Useful packages mentioned in the answer:
mdg:validated-method
alanning:roles
audit-argument-checks