On Aug 17, 2012, at 11:30 AM, Shawn McElroy <
lucky...@gmail.com> wrote:
> Yea it makes sense now. It just so different than what I'm used to. Where models are where a lot of the core app functionality which, if the end user could see, could allow them to easily copy your code which you would not want. But here the model is exposed. But since the focus on meteor is having a local client db to make the site appear real time, it makes sense to me. so here in the models I would only have the minimal code needed for the app to function properly.
>
> Which begs the question, for code I dont want end users to see that I would normally have in a model, or a controller, where would I put that? For controllers and what I am used to, the controllers handle all the communication between model and view. the model validates and returns the dataset, and the controller, if needed, preps the data to be available in the view. The way meteor works, I would need that kind of info on both client and server as well. Which I would probable end up all just putting into the models here.
>
> So for code I dont want end users to see I would put it in the lib or server directories. but short of server side validation and maybe some schema definitions, or server/app configs, I dont see a lot else I would put in there. I just want to be able to prevent users from being able to capture code and being able to use it (for proprietary apps, which I would make at my job). While I love the idea of meteor and how it works, it so far, seems to me that the vast majority of your application code is visible to the end user. Granted it is all minified/obfuscated which makes it more difficult. Just for the apps I make at my job, code security is of high importance. And for those kinds of apps, meteor may not be as much as a fit as I need it to be.
I think perhaps a better way to think of it is: "I'm writing an app that lives in the browser". Everything lives in the browser - including the database (mongoDB)! That means everything - views, models, logic, controllers and data storage - all lives in the browser.
Meteor adds special magic so that what happens in the browser is automatically reflected on the server and pushed out to other people running their apps in other browsers. "Meteor + server" is really just magic "sync and shard" technology to keep all the databases (minimongo) in the apps running in each person's browser in sync and to "shard" the data (using the server "publish" functions) so that people only see the slices of data they should (depending on your app design, permissions, etc). In general, you should never need to really think about this other than how to manage the "publish" functions to ensure clients only get the data they should.
On a practical level, Meteor on the server is also where you have to perform re-validation of data to prevent rogue clients, script kiddies, etc from corrupting the shared database or accessing data they shouldn't. e.g. someone on the client updated the mongodb database (minimongo) running in the browser - before I write it to the shared database on the server, I'll rerun the validation to ensure the data is OK then allow/reject the write/sync. This should be the same validation logic you run on the client before writing it to the browser's minimongo so code reuse should be nearly 100%.
Finally, Meteor.methods() allows you to write the server-side services that you simply can't implement in a browser-only app - and those services can be thought of like accessing any other "remote" API from a browser-only app. E.g. I want to access an ERP system - obviously you can't do that within the browser so you Meteor.call a Meteor.method that runs access code on the server, and returns results.
As for code security, you are correct in that a lot of the application code for a normal Meteor app will typically be exposed in the client (minified and obfuscated but it's still there to be reverse engineered). My guess is that depending on your use case and application design this could be a problem. I think that's especially true if you don't want all your page templates available in the browser since Meteor doesn't provide any way to control what is pushed to the browser (they may add an API for it but it's definitely not present now). Meteor certainly makes it easier to pull all the page templates but most web apps aren't that hard to reverse engineer so any security by obscurity is really just a false sense of "being secure". I think this is an area where Meteor support is currently very limited - but also an area where future Meteor improvements will probably focus (I know a lot of related features are on the drawing boards).
I think in most cases, most web apps won't really be less "code insecure" with Meteor. But if you are doing really unique things at the browser level (like your page layout or navigation/page-flow depends on proprietary code you don't want exposed e.g. order the page links in a certain way to Thursdays in odd hours, but all other days except saturdays, use another layout, etc) then Meteor will probably not be for you.
Of course, the framework is young - just thinking about that example, those use-cases may be addressed in the future - localization and browser detection (mobile vs desktop vs tablet) features that are on the roadmap could allow you to serve different templates to different users for different reasons (all defined on the server)... :)
-iain