Add regexp tame to ses
MODIFY
packages/lockdown-shim/package.json
packages/lockdown-shim/package.json
"@agoric/tame-function-constructors": "0.1.0",
"@agoric/tame-global-date-object": "0.1.0",
"@agoric/tame-global-error-object": "0.1.0",
- "@agoric/tame-global-math-object": "0.1.0"
+ "@agoric/tame-global-math-object": "0.1.0",
+ "@agoric/tame-global-regexp-object": "0.1.0"
},
"devDependencies": {
"babel-eslint": "^10.0.3",

MODIFY
packages/lockdown-shim/src/main.js
packages/lockdown-shim/src/main.js
@@ -18,8 +18,9 @@ import repairLegacyAccessors from '@agoric/repair-legacy-accessors';
import tameFunctionConstructors from '@agoric/tame-function-constructors';
import tameGlobalDateObject from '@agoric/tame-global-date-object';
-import tameGlobalMathObject from '@agoric/tame-global-math-object';
import tameGlobalErrorObject from '@agoric/tame-global-error-object';
+import tameGlobalMathObject from '@agoric/tame-global-math-object';
+import tameGlobalRegExpObject from '@agoric/tame-global-regexp-object';
import enablePropertyOverrides from '@agoric/enable-property-overrides';
import makeHardener from '@agoric/make-hardener';
@@ -28,8 +29,9 @@ import Compartment from '@agoric/compartment-shim';
export function lockdown(options = {}) {
const {
noTameDate = false,
- noTameMath = false,
noTameError = false,
+ noTameMath = false,
+ noTameRegExp = false,
registerOnly = false,
} = options;
@@ -43,12 +45,16 @@ export function lockdown(options = {}) {
tameGlobalDateObject();
}
+ if (!noTameError) {
+ tameGlobalErrorObject();
+ }
+
if (!noTameMath) {
tameGlobalMathObject();
}
- if (!noTameError) {
- tameGlobalErrorObject();
+ if (!noTameRegExp) {
+ tameGlobalRegExpObject();
}
/**

ADD
packages/lockdown-shim/test/tame-rexexp-allow.test.js
+/* global Compartment */
+import test from 'tape';
+import { lockdown } from '../src/main.js';
+
+const unsafeRegExp = RegExp;
+
+lockdown({ noTameRegExp: true });
+
+test('lockdown() default - RegExp from Compartment is tamed', t => {
+ const c = new Compartment();
+ const actualRegExp = c.evaluate('RegExp');
+
+ t.equal(actualRegExp, unsafeRegExp, 'RegExp should be native');
+
+ t.end();
+});
+
+test('lockdown() default - RegExp from nested Compartment is tamed', t => {
+ const c = new Compartment().evaluate('new Compartment()');
+ const actualRegExp = c.evaluate('RegExp');
+
+ t.equal(actualRegExp, unsafeRegExp, 'RegExp should be native');
+
+ t.end();
+});

ADD
packages/lockdown-shim/test/tame-rexexp.test.js
+/* global Compartment */
+import test from 'tape';
+import { lockdown } from '../src/main.js';
+
+lockdown();
+
+test('lockdown() RegExp allowed - RegExp from Compartment is not tamed', t => {
+ const c = new Compartment();
+ const properties = c.evaluate('Reflect.ownKeys(RegExp)');
+
+ t.deepEqual(
+ properties.sort(),
+ ['length', 'name', 'prototype'].sort(),
+ 'RegExp should not have static properties',
+ );
+
+ t.end();
+});
+
+test('lockdown() RegExp allowed - RegExp from nested Compartment not is tamed', t => {
+ const c = new Compartment().evaluate('new Compartment()');
+ const properties = c.evaluate('Reflect.ownKeys(RegExp)');
+
+ t.deepEqual(
+ properties.sort(),
+ ['length', 'name', 'prototype'].sort(),
+ 'RegExp should not have static properties',
+ );
+
+ t.end();
+});

Add regexp tame to ses