Reputation: 1
I am storing some sensitive data on javascript side. How can I prevent user from tampering these data. I can not do this on server side with ajax or anything else, as smoothness of the animation concerned.
Upvotes: 0
Views: 92
Reputation: 34489
Make your JavaScript inaccessible to someone using function scope etc. This isn't perfect but it can certainly make things a lot harder. For example, if you define:
var f = function() { return "test"; }
f();
Then it's easy to call window.f()
If instead you define as a self invoking function then you've just made it much more difficult for someone to call:
(function() {
return test;
})();
This principle can then be extended - any variables defined within the function, will only have scope within it making it very difficult (but probably not impossible) to get hold of them.
Upvotes: 2