Skip to content

Commit

Permalink
Export a public interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Mar 14, 2016
1 parent 84c8666 commit 35774a1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SES5

> Secure EcmaScript 5
*:warning: This is not an official, working packaging of Google Caja’s SES.
This is a project attempting to bring SES to Node.js. There remain a few
surmountable obstacles before we achieve proper confinement.*

SES5 is a tool that allows mutually suspicious programs to share a single
EcmaScript 5 compliant JavaScript context without interfering with each
other. It does this by freezing everything that is accessible in global
scope, removing interfaces that would allow programs to interfe with
each-other, and providing the ability to evaluate arbitrary code in
isolation.

Usage:

```js
var ses = require('ses5');
ses.confine(`
log("Hello, Outside World!")
`, {
log: function log(message) {
console.log(message);
}
});
```

```
Repaired: Non-deletable RegExp statics are a global communication channel
Repaired: Date.prototype is a global communication channel
Not repaired: Date.prototype should be a plain object
Not repaired: RegExp.prototype should be a plain object
Not repaired: %ThrowTypeError% has normal function properties
Max Severity: Safe spec violation(1).
230 Deleted
215 Frozen harmless
41 Globals are not readonly data properties
44 Globals changed inexplicably
44 Globals wre not made readonly
1 Skipped
Max Severity: New symptom(6) is not SES-safe.
initSES succeeded.
Hello, Outside World!
```
3 changes: 3 additions & 0 deletions cheat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This severity is too high for any use other than development.
var ses = ses || {};
ses.maxAcceptableSeverityName = 'NEW_SYMPTOM';
8 changes: 8 additions & 0 deletions demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var ses = require('./ses');
ses.confine(`
log("Hello, Outside World!")
`, {
log: function log(message) {
console.log(message);
}
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "ses5",
"version": "0.0.0",
"description": "Secure ECMAScript 5",
"main": "./ses.js",
"scripts": {
"test": "true"
},
Expand Down
30 changes: 30 additions & 0 deletions ses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var fs = require('fs');
var path = require('path');
var vm = require('vm');

var initSES = [
"cheat.js", // XXX
"logger.js",
"repair-framework.js",
"repairES5.js",
"WeakMap.js",
"debug.js",
"StringMap.js",
"whitelist.js",
"atLeastFreeVarNames.js",
"startSES.js",
"ejectorsGuardsTrademarks.js",
"hookupSESPlus.js",
].map(function (name) {
return fs.readFileSync(path.join(__dirname, name), 'utf8');
}).join('\n');

var global = {};
global.console = console;
global.global = global;
var context = vm.createContext(global);
var caja = vm.runInContext(initSES, context);

exports.confine = global.cajaVM.confine;

0 comments on commit 35774a1

Please sign in to comment.