A
A
artch2015-01-16 12:49:04
Node.js
artch, 2015-01-16 12:49:04

Hiding global access in node.js?

Task: to make it so that some code executing on the server through eval (or through the function constructor, it doesn’t matter) in any way could not access the global object and require.
A simple solution:

function runCode(code) {
  var global, require; 
  eval(code);
}

// evaled code:
console.log(global); // -> undefined

Solution workaround:
// evaled code:  
var global = eval("(new ('hello'.constructor.constructor)('return global;'))()");
console.log(global); // !!!

Question: how to more securely hide the global so that this workaround doesn't work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Pushkarev, 2015-01-16
@artch

vm.runInNewContext

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question