Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes sandbox can be broken #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/shovel.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function getSafeRunner() {

global.print = send.bind(global, 'stdout');
global.console = { log: send.bind(global, 'stdout') };
global.process = {
global.process = {
stdout: { write: send.bind(global, 'stdout') }
};
global.postMessage = send.bind(global, 'message');
Expand All @@ -51,9 +51,9 @@ function getSafeRunner() {
// Run code
function run() {

var context = vm.createContext();
var context = vm.createContext(Object.create(null));
var safeRunner = vm.runInContext('('+getSafeRunner.toString()+')()', context);

try {
safeRunner({
send: function (event, value) {
Expand Down Expand Up @@ -84,7 +84,7 @@ function run() {
}

process.on('message', processMessageListener.bind(null, context));

process.send('__sandbox_inner_ready__');

// This will exit the process if onmessage was not defined
Expand Down
10 changes: 8 additions & 2 deletions test/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('Sandbox', function() {
done();
});
});

it('should queue messages posted before the sandbox is ready and process them once it is', function(done){
var messageHandler = sinon.spy();
var num_messages_sent = 0;
Expand All @@ -116,4 +116,10 @@ describe('Sandbox', function() {
});
});

});
it('should not be exploitable via constructor', function(done) {
sb.run(`new Function("return (this.constructor.constructor('return (this.process.mainModule.constructor._load)')())")()("util").inspect("hi")`, function(output){
output.result.should.eql("'TypeError: Cannot read property \\'constructor\\' of undefined'");
done();
})
})
});