Skip to content

Commit

Permalink
fix(ses): missing native function markings
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jun 17, 2023
1 parent 4a501cf commit 98b9698
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions packages/ses/src/lockdown-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export const repairIntrinsics = (options = {}) => {

tameDomains(domainTaming);

// Replace Function.prototype.toString with one that recognizes
// shimmed functions as honorary native functions.
const markVirtualizedNativeFunction = tameFunctionToString();

const { addIntrinsics, completePrototypes, finalIntrinsics } =
makeIntrinsicsCollector();

Expand Down Expand Up @@ -304,10 +308,6 @@ export const repairIntrinsics = (options = {}) => {
// Replace *Locale* methods with their non-locale equivalents
tameLocaleMethods(intrinsics, localeTaming);

// Replace Function.prototype.toString with one that recognizes
// shimmed functions as honorary native functions.
const markVirtualizedNativeFunction = tameFunctionToString();

/**
* 2. WHITELIST to standardize the environment.
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/ses/src/permits-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ export default function whitelistIntrinsics(
}

if (typeof obj === 'function') {
markVirtualizedNativeFunction(obj);
if (objectHasOwnProperty(FunctionInstance, permitProp)) {
return FunctionInstance[permitProp];
}
Expand All @@ -261,6 +260,10 @@ export default function whitelistIntrinsics(
const protoName = permit['[[Proto]]'];
visitPrototype(path, obj, protoName);

if (typeof obj === 'function') {
markVirtualizedNativeFunction(obj);
}

for (const prop of ownKeys(obj)) {
const propString = asStringPropertyName(path, prop);
const subPath = `${path}.${propString}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/ses/src/permits.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ export const permitted = {
constructor: '%InertFunction%',
toString: fn,
'@@hasInstance': fn,
// proposed but not yet std yet. To be removed if there
// proposed but not yet std. To be removed if there
caller: false,
// proposed but not yet std yet. To be removed if there
// proposed but not yet std. To be removed if there
arguments: false,
},

Expand Down
2 changes: 2 additions & 0 deletions packages/ses/test/test-evalTaming-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ test('safe eval when evalTaming is undefined.', t => {
compartment.evaluate('(1, eval)("1 + 1")');
// eslint-disable-next-line no-eval
t.is(eval.toString(), 'function eval() { [native code] }');
// eslint-disable-next-line no-eval
t.is(eval.toString.toString(), 'function toString() { [native code] }');
});

0 comments on commit 98b9698

Please sign in to comment.