fix(ses): Fix lockdown layer pollution from module layer
MODIFY
packages/ses/NEWS.md
packages/ses/NEWS.md
@@ -2,7 +2,8 @@ User-visible changes in SES:
## Next release
-* No changes yet.
+* Fixes an exception thrown when calling `lockdown` after just importing
+ `ses/lockdown` in all environments.
## Release 0.10.3 (8-September-2020)

MODIFY
packages/ses/lockdown.js
packages/ses/lockdown.js
import { assign } from './src/commons.js';
import { tameFunctionToString } from './src/tame-function-tostring.js';
import { getGlobalIntrinsics } from './src/intrinsics.js';
+import { getAnonymousIntrinsics } from './src/get-anonymous-intrinsics.js';
import { makeLockdown, harden } from './src/lockdown-shim.js';
import {
makeCompartmentConstructor,
@@ -35,6 +36,10 @@ const Compartment = makeCompartmentConstructor(
assign(globalThis, {
harden,
- lockdown: makeLockdown(makeCompartmentConstructor, CompartmentPrototype),
+ lockdown: makeLockdown(
+ makeCompartmentConstructor,
+ CompartmentPrototype,
+ getAnonymousIntrinsics,
+ ),
Compartment,
});

MODIFY
packages/ses/ses.js
packages/ses/ses.js
import { assign } from './src/commons.js';
import { tameFunctionToString } from './src/tame-function-tostring.js';
import { getGlobalIntrinsics } from './src/intrinsics.js';
+import { getModularAnonymousIntrinsics } from './src/get-anonymous-intrinsics.js';
import { makeLockdown, harden } from './src/lockdown-shim.js';
import { whitelist, modulesWhitelist } from './src/whitelist.js';
import {
@@ -40,6 +41,7 @@ assign(globalThis, {
lockdown: makeLockdown(
makeModularCompartmentConstructor,
CompartmentPrototype,
+ getModularAnonymousIntrinsics,
),
Compartment: ModularCompartment,
StaticModuleRecord,

MODIFY
packages/ses/src/get-anonymous-intrinsics.js
packages/ses/src/get-anonymous-intrinsics.js
@@ -108,8 +108,14 @@ export function getAnonymousIntrinsics() {
'%ThrowTypeError%': ThrowTypeError,
'%TypedArray%': TypedArray,
'%InertCompartment%': InertCompartment,
- '%InertStaticModuleRecord%': InertStaticModuleRecord,
};
return intrinsics;
}
+
+export function getModularAnonymousIntrinsics() {
+ return {
+ ...getAnonymousIntrinsics(),
+ '%InertStaticModuleRecord%': InertStaticModuleRecord,
+ };
+}

MODIFY
packages/ses/src/lockdown-shim.js
packages/ses/src/lockdown-shim.js
@@ -27,7 +27,6 @@ import tameMathObject from './tame-math-object.js';
import tameRegExpConstructor from './tame-regexp-constructor.js';
import enablePropertyOverrides from './enable-property-overrides.js';
import tameLocaleMethods from './tame-locale-methods.js';
-import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
import { initGlobalObject } from './global-object.js';
import { initialGlobalPropertyNames } from './whitelist.js';
import { tameFunctionToString } from './tame-function-tostring.js';
@@ -52,6 +51,7 @@ const alreadyHardenedIntrinsics = () => false;
export function repairIntrinsics(
makeCompartmentConstructor,
compartmentPrototype,
+ getAnonymousIntrinsics,
options = {},
) {
// First time, absent options default to 'safe'.
@@ -176,11 +176,13 @@ export function repairIntrinsics(
export const makeLockdown = (
makeCompartmentConstructor,
compartmentPrototype,
+ getAnonymousIntrinsics,
) => {
const lockdown = (options = {}) => {
const maybeHardenIntrinsics = repairIntrinsics(
makeCompartmentConstructor,
compartmentPrototype,
+ getAnonymousIntrinsics,
options,
);
return maybeHardenIntrinsics();

MODIFY
packages/ses/test/compartment-prototype.test.js
packages/ses/test/compartment-prototype.test.js
import tap from 'tap';
import '../lockdown.js';
+lockdown({ errorTaming: 'unsafe' });
+
const { test } = tap;
test('Compartment prototype', t => {

MODIFY
packages/ses/test/lockdown-options.test.js
packages/ses/test/lockdown-options.test.js
import test from 'tape';
import { makeLockdown } from '../src/lockdown-shim.js';
+import { getAnonymousIntrinsics } from '../src/get-anonymous-intrinsics.js';
+import {
+ makeCompartmentConstructor,
+ CompartmentPrototype,
+} from '../src/compartment-shim.js';
-const lockdown = makeLockdown();
+const lockdown = makeLockdown(
+ makeCompartmentConstructor,
+ CompartmentPrototype,
+ getAnonymousIntrinsics,
+);
test('lockdown throws with non-recognized options', t => {
t.plan(2);

MODIFY
packages/ses/test/whitelist-intrinsics.test.js
packages/ses/test/whitelist-intrinsics.test.js
import tap from 'tap';
import '../ses.js';
import { repairIntrinsics } from '../src/lockdown-shim.js';
+import { getModularAnonymousIntrinsics } from '../src/get-anonymous-intrinsics.js';
import {
makeCompartmentConstructor,
CompartmentPrototype,
@@ -28,6 +29,7 @@ test('whitelistPrototypes - on', t => {
const hardenIntrinsics = repairIntrinsics(
makeCompartmentConstructor,
CompartmentPrototype,
+ getModularAnonymousIntrinsics,
);
console.timeEnd('Benchmark repairIntrinsics()');

fix(ses): Fix lockdown layer pollution from module layer (#472)