This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: implement vm.moveMessagePortToContext()
This should help a lot with actual sandboxing of JS code.
- Loading branch information
Showing
9 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef SRC_NODE_CONTEXTIFY_H_ | ||
#define SRC_NODE_CONTEXTIFY_H_ | ||
|
||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
#include "v8.h" | ||
|
||
namespace node { | ||
|
||
class Environment; | ||
|
||
v8::MaybeLocal<v8::Context> ContextFromContextifiedSandbox( | ||
Environment* env, | ||
v8::Local<v8::Object> sandbox); | ||
|
||
} // namespace node | ||
|
||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
|
||
#endif // SRC_NODE_CONTEXTIFY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* eslint-disable prefer-assert-methods */ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const vm = require('vm'); | ||
const { MessageChannel } = require('worker'); | ||
|
||
{ | ||
const context = vm.createContext(); | ||
const channel = new MessageChannel(); | ||
context.port = vm.moveMessagePortToContext(channel.port1, context); | ||
context.global = context; | ||
const port = channel.port2; | ||
vm.runInContext('(' + function() { | ||
function assert(condition) { if (!condition) throw new Error(); } | ||
|
||
{ | ||
assert(port instanceof Object); | ||
assert(port.onmessage === undefined); | ||
assert(port.postMessage instanceof Function); | ||
port.onmessage = function(msg) { | ||
assert(msg instanceof Object); | ||
port.postMessage(msg); | ||
}; | ||
port.start(); | ||
} | ||
|
||
{ | ||
let threw = false; | ||
try { | ||
port.postMessage(global); | ||
} catch (e) { | ||
assert(e instanceof Object); | ||
assert(e instanceof Error); | ||
threw = true; | ||
} | ||
assert(threw); | ||
} | ||
} + ')()', context); | ||
port.on('message', common.mustCall((msg) => { | ||
assert(msg instanceof Object); | ||
port.close(); | ||
})); | ||
port.postMessage({}); | ||
} |