Block eval && new Function
Well, also you have module
variable in node
. So you can require vm
package and run code using its require
method:
var vm = module.require('vm');
vm.runInThisContext(' console.log("hello") ');
UPD Well, you updated the question, but we can hack it again:
var vm = module.constructor.prototype.require('vm');
vm.runInThisContext(' console.log("hello") ');
UPD2 Another variant:
var vm = module.constructor._load('vm');
vm.runInThisContext(' console.log("hello") ');
UPD3 Again conditions are changed so the next variant:
module.constructor.prototype._compile(' console.log("again hacked") ');
// or
module.__proto__._compile(' console.log("again hacked") ');
// or
Object.getPrototypeOf(module)._compile(' console.log("again hacked") ');
I think better to set module = undefined
to make question more complex:)
UPD4
There are another variant without module
:)
process.stdin.push(' console.log("here we are") \n ');
But it works only in CLI ("repl")
UPD5
Also in iojs
and in node
with version >= 0.11.x you can use contextify
binding:
var contextify = process.binding('contextify');
var script = new contextify.ContextifyScript(' console.log("im here, buddy") ');
script.runInThisContext();
In node
with version < 0.11.x you can use evals
binding:
var evals = process.binding('evals');
var script = new evals.NodeScript(' console.log("here I am") ')
script.runInThisContext();
module.require = undefined;
is not enough as require
is inherited from the Module prototype:
module.require = undefined;
var vm = module.__proto__.require('vm');
vm.runInThisContext('console.log(1)');
Instead, you should:
module.__proto__.require = undefined;
// now this fails and you can't use the __proto__ trick:
var vm = module.require('vm');