沙箱中的Nodejs [英] Nodejs in sandbox
问题描述
我使用nodejs作为客户端浏览器和服务器之间的中间人来处理所有请求。我正在尝试使用nodejs作为过滤工具,并突出显示(如果不是)所有恶意脚本。但我意识到nodejs允许脚本以当前环境特权运行。因此,我决定通过安装沙箱( npm install sandbox
或 git clone git://github.com/gf3/)在新的上下文中运行它sandbox.git
)。
但是当我运行节点时出现以下错误:
I'm using nodejs as a middle-man between a client browser and the server to handle all the requests. I'm trying to use nodejs as a filter tool and highlight (if not) all malicious scripts. But I realize that nodejs let the script to run with the current environment privilege. So, I decide to run it in a new context by installing sandbox (npm install sandbox
or git clone git://github.com/gf3/sandbox.git
).
However when I run node I have this following error:
TypeError:无法调用方法
\'runInNewContext \'of undefined'
TypeError: Cannot call method \'runInNewContext\' of undefined'
任何人的想法?
推荐答案
您是否看过的inbuild沙箱功能节点0.4.6 。
var localVar = 123,
usingscript, evaled,
vm = require('vm');
usingscript = vm.runInThisContext('localVar = 1;',
'myfile.vm');
console.log('localVar: ' + localVar + ', usingscript: ' +
usingscript);
evaled = eval('localVar = 1;');
console.log('localVar: ' + localVar + ', evaled: ' +
evaled);
// localVar: 123, usingscript: 1
// localVar: 1, evaled: 1
这篇关于沙箱中的Nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!