Reputation: 12477
My only requirement for executing this arbitrary js code is that certain global variables/functions (e.g. setInterval
) are not exposed.
My current strategy involves parsing through the js code and making a var
declaration (at the beginning of the enclosing closure) for every global reference.
I'm wondering if there's any other obvious way to solving this.
Also just to clarify, this arbitrary code is not being run with things like eval
. Rather, it's being wrapped inside a closure and appended to the base code.
Upvotes: 0
Views: 512
Reputation: 7452
One of the options is to override the globals by supplying your own function or variables. Example:
window.alert = function() {
// your code goes here
// Optionally call window.alert if needed
}
This should be manageable if you have a small finite list of things you wish to hide. This will make them globally unavailable.
Upvotes: 1