Comparing version 0.1.3 to 0.2.0
@@ -75,3 +75,3 @@ console.log('starting'); | ||
document.getElementById('dateNowStatus').textContent = 'Date.now() enabled'; | ||
options.dateNowTrap = false; | ||
options.dateNowMode = "allow"; | ||
} | ||
@@ -78,0 +78,0 @@ const r = SES.makeSESRootRealm(options); |
@@ -180,4 +180,4 @@ # SES Demo | ||
The SES environment normally replaces ``Date.now()`` with a function that | ||
only returns ``NaN``. But this can be disabled by setting a configuration | ||
option named ``dateNowTrap`` to ``false``. | ||
only returns ``NaN``. But ``Date.now()`` can be re-enabled by setting a | ||
configuration option named ``dateNowMode`` to ``allow``. | ||
@@ -184,0 +184,0 @@ (Note that this API is still in flux, and we might change it in the future. |
{ | ||
"name": "ses", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Secure ECMAScript", | ||
@@ -10,9 +10,9 @@ "main": "src/index.js", | ||
"build-intermediate": "node scripts/build-intermediate.js", | ||
"build": "node scripts/build-intermediate.js && rollup --format=iife --output.name=SES --sourcemap --file=dist/ses-shim.js -- src/index.js" | ||
"build": "git submodule update --init --recursive && node scripts/build-intermediate.js && rollup --format=iife --output.name=SES --output.exports=named --sourcemap --file=dist/ses-shim.js -- src/index.js" | ||
}, | ||
"devDependencies": { | ||
"esm": "^3.0.37", | ||
"rollup": "^0.63.4", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"tape": "^4.9.0" | ||
"esm": "^3.1.0", | ||
"rollup": "^1.1.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"tape": "^4.9.2" | ||
}, | ||
@@ -19,0 +19,0 @@ "dependencies": {}, |
@@ -30,2 +30,11 @@ # Secure EcmaScript (SES) | ||
### Install | ||
`npm install` | ||
`npm run build` | ||
Run the test suite | ||
`npm test` | ||
### Bug Disclosure | ||
@@ -32,0 +41,0 @@ |
@@ -55,4 +55,11 @@ const rollup = require('rollup'); | ||
bundle().then(function(o) { | ||
let { code, map } = o; | ||
process(code, map); | ||
const { output } = o; | ||
for (const chunkOrAsset of output) { | ||
if (chunkOrAsset.isAsset) { | ||
throw Error(`not expecting an asset: ${chunkOrAsset.fileName}`); | ||
} | ||
const { code, map } = chunkOrAsset; | ||
process(code, map); | ||
return; // there should be only one chunk, hopefully | ||
} | ||
}); | ||
@@ -59,0 +66,0 @@ } |
@@ -15,10 +15,40 @@ // Copyright (C) 2018 Agoric | ||
import tameDate from './tame-date.js'; | ||
import tameMath from './tame-math.js'; | ||
import tameIntl from './tame-intl.js'; | ||
import tameError from './tame-error.js'; | ||
import tameRegExp from './tame-regexp.js'; | ||
export function createSESWithRealmConstructor(creatorStrings, Realm) { | ||
function makeSESRootRealm(options) { | ||
options = Object(options); // Todo: sanitize | ||
const r = Realm.makeRootRealm(); | ||
let shims = []; | ||
// "allow" enables real Date.now(), anything else gets NaN | ||
// (it'd be nice to allow a fixed numeric value, but too hard to | ||
// implement right now) | ||
if (options.dateNowMode !== "allow") { | ||
shims.push(`(${tameDate})();`); | ||
} | ||
if (options.mathRandomMode !== "allow") { | ||
shims.push(`(${tameMath})();`); | ||
} | ||
if (options.intlMode !== "allow") { | ||
shims.push(`(${tameIntl})();`); | ||
} | ||
if (options.errorStackMode !== "allow") { | ||
shims.push(`(${tameError})();`); | ||
} | ||
if (options.regexpMode !== "allow") { | ||
shims.push(`(${tameRegExp})();`); | ||
} | ||
const r = Realm.makeRootRealm({shims: shims}); | ||
const b = r.evaluate(creatorStrings); | ||
b.createSESInThisRealm(r.global, creatorStrings, r); | ||
//b.removeProperties(r.global); | ||
b.tamePrimordials(r.global, options); | ||
r.global.def = b.def; | ||
@@ -25,0 +55,0 @@ r.global.Nat = b.Nat; |
@@ -21,3 +21,3 @@ // Adapted from SES/Caja - Copyright (C) 2011 Google Inc. | ||
export function deepFreeze(primordialRoots) { | ||
export function deepFreeze(root) { | ||
@@ -31,3 +31,3 @@ const { freeze, getOwnPropertyDescriptors, getPrototypeOf } = Object; | ||
/** | ||
* "deepFreeze()" acts like "Object.freeze()", except that: | ||
* "innerDeepFreeze()" acts like "Object.freeze()", except that: | ||
* | ||
@@ -38,3 +38,3 @@ * To deepFreeze an object is to freeze it and all objects transitively | ||
*/ | ||
function deepFreeze(node) { | ||
function innerDeepFreeze(node) { | ||
// Objects that we have frozen in this round. | ||
@@ -118,3 +118,4 @@ const freezingSet = new Set(); | ||
deepFreeze(primordialRoots); | ||
innerDeepFreeze(root); | ||
return root; | ||
} | ||
@@ -121,0 +122,0 @@ |
@@ -18,2 +18,5 @@ // Copyright (C) 2018 Agoric | ||
export function def(node) { | ||
// TODO HACK return a shallow freeze unless Object.prototype is frozen. | ||
// This detects whether we are in a SES realm. | ||
// TODO: this currently does too much work: it doesn't remember what's been | ||
@@ -27,4 +30,8 @@ // frozen already, so it will re-freeze things like Function.prototype | ||
deepFreeze(node); | ||
if (Object.isFrozen(Object.prototype)) { | ||
deepFreeze(node); | ||
} else { | ||
Object.freeze(node); | ||
} | ||
return node; | ||
} |
@@ -18,3 +18,2 @@ // Copyright (C) 2018 Agoric | ||
import { removeProperties } from './removeProperties.js'; | ||
import { tamePrimordials } from './tame.js'; | ||
import { getAnonIntrinsics } from './anonIntrinsics.js'; | ||
@@ -25,4 +24,4 @@ import { def } from './def.js'; | ||
export { createSESWithRealmConstructor, createSESInThisRealm, | ||
deepFreezePrimordials, removeProperties, tamePrimordials, getAnonIntrinsics, | ||
deepFreezePrimordials, removeProperties, getAnonIntrinsics, | ||
def, Nat | ||
}; |
@@ -16,4 +16,12 @@ // Copyright (C) 2018 Agoric | ||
import SES from './SES.js'; | ||
import { def, Nat } from './bundle/index.js'; | ||
const makeSESRootRealm = SES.makeSESRootRealm; | ||
export default SES; | ||
export { def, Nat, SES, makeSESRootRealm }; | ||
// this should be usable like: | ||
// import SES from 'SES'; let r = SES.makeSESRootRealm(); | ||
// const SES = require("SES"); let r = SES.makeSESRootRealm(); | ||
// import {SES, def, Nat} from 'SES'; | ||
// f = compileExpr(source); then f(imports) can only affect 'imports' | ||
@@ -20,0 +28,0 @@ //exports.compileExpr = function(exprSrc, opt_mitigateOpts) { }; |
@@ -9,2 +9,4 @@ import test from 'tape'; | ||
t.equal(Number.isNaN(now), true); | ||
const newDate = s.evaluate('new Date()'); | ||
t.equal(`${newDate}`, "Invalid Date"); | ||
t.end(); | ||
@@ -14,6 +16,8 @@ }); | ||
test('Date.now neutered upon request', function(t) { | ||
const s = SES.makeSESRootRealm({dateNowTrap: true}); | ||
const s = SES.makeSESRootRealm({dateNowMode: false}); | ||
t.equal(s.evaluate('Date.parse("1982-04-09")'), Date.parse('1982-04-09')); | ||
const now = s.evaluate('Date.now()'); | ||
t.equal(Number.isNaN(now), true); | ||
const newDate = s.evaluate('new Date()'); | ||
t.equal(`${newDate}`, "Invalid Date"); | ||
t.end(); | ||
@@ -24,3 +28,3 @@ }); | ||
const start = Date.now(); | ||
const s = SES.makeSESRootRealm({dateNowTrap: false}); | ||
const s = SES.makeSESRootRealm({dateNowMode: "allow"}); | ||
t.equal(s.evaluate('Date.parse("1982-04-09")'), Date.parse('1982-04-09')); | ||
@@ -31,3 +35,28 @@ const now = s.evaluate('Date.now()'); | ||
t.assert(start <= now <= finished, (start, now, finished)); | ||
const newDate = s.evaluate('new Date()'); | ||
t.notEqual(`${newDate}`, "Invalid Date"); | ||
t.end(); | ||
}); | ||
// neither of these are supposed to work | ||
test('get Date from new SES.makeSESRootRealm', function(t) { | ||
const s1 = SES.makeSESRootRealm(); // disable Date | ||
const s2 = s1.evaluate('SES.makeSESRootRealm({dateNowMode: "allow"})'); // reenable | ||
const now = s2.global.Date.now(); | ||
t.equal(Number.isNaN(now), true); | ||
const newDate = s2.evaluate('new Date()'); | ||
t.equal(`${newDate}`, "Invalid Date"); | ||
t.end(); | ||
}); | ||
test('get Date from new Realm', function(t) { | ||
const s1 = SES.makeSESRootRealm({dateNowMode: false}); | ||
const r2 = s1.evaluate('Realm.makeRootRealm()'); | ||
const now = r2.global.Date.now(); | ||
console.log("now is", now); | ||
t.equal(Number.isNaN(now), true); | ||
const newDate = r2.evaluate('new Date()'); | ||
t.equal(`${newDate}`, "Invalid Date"); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1033553
136
10832
67