You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
I'm working to use require in sandbox mode but what I'm finding is that if one module requires another module they are contextified to the point the original module may have a problem using it. Example:
//This is a simplified example from the popular jws module (data-stream.js)
var Stream = require('stream');
var util = require('util');
function DataStream(data) {
//(whatever in here)
}
util.inherits(DataStream, Stream);
DataStream.prototype.write = function write(data) {
this.buffer = Buffer.concat([this.buffer, Buffer.from(data)]);
this.emit('data', data);
};
I understand that if the module were to build its class (write to prototype) before extending the child required module everything would be fine. But this highlights one of many problems I'm running in to with child require calls.
let requireParentVm = new NodeVM({
sandbox: {},
console: 'off', //TODO: make this redirect and capture console.log events for user
require: {
external: true,
builtin: ['buffer', 'stream', 'util' ],
root: '/tmp/node_modules',
mock: {},
context: 'sandbox'
},
nesting: false,
wrapper: 'commonjs' });
requireParentVm.run(`module.exports = {}; module.exports['jws'] = require('jws');`) // <-- throws with set on proxy: trap returned falsish
It would be nice if sub require calls brought the module in to the same context as the already contexified original require call without all the proxies (since the context its running in will already proxy any results).
I've tried to nest vms as well, but did not have any luck.
Maybe I'm missing something?
My goal is to require a bunch of modules (and their dependencies) in a protected way (keeping them from interacting with global, but having them each share each others context).
Thanks
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello,
I'm working to use require in sandbox mode but what I'm finding is that if one module requires another module they are contextified to the point the original module may have a problem using it. Example:
I understand that if the module were to build its class (write to prototype) before extending the child required module everything would be fine. But this highlights one of many problems I'm running in to with child require calls.
It would be nice if sub require calls brought the module in to the same context as the already contexified original require call without all the proxies (since the context its running in will already proxy any results).
I've tried to nest vms as well, but did not have any luck.
Maybe I'm missing something?
My goal is to require a bunch of modules (and their dependencies) in a protected way (keeping them from interacting with global, but having them each share each others context).
Thanks
The text was updated successfully, but these errors were encountered: