From ce43f371c03ae84f32a3aab4a87c5276bd221e22 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:28:36 +0000 Subject: [PATCH 1/3] fix(ses): removeUnpermittedIntrinsics on Hermes via dynamic permit at runtime --- packages/ses/src/permits.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/ses/src/permits.js b/packages/ses/src/permits.js index c5745903ee..13432ad689 100644 --- a/packages/ses/src/permits.js +++ b/packages/ses/src/permits.js @@ -1,7 +1,7 @@ /* eslint-disable no-restricted-globals */ /* eslint max-lines: 0 */ -import { arrayPush } from './commons.js'; +import { arrayPush, getOwnPropertyNames, arrayForEach } from './commons.js'; /** @import {GenericErrorConstructor} from '../types.js' */ @@ -299,6 +299,22 @@ const accessor = { set: fn, }; +// eslint-disable-next-line func-names +const strict = function () { + 'use strict'; +}; + +arrayForEach(getOwnPropertyNames(strict), prop => { + try { + strict[prop]; + } catch (e) { + // https://github.com/facebook/hermes/blob/main/test/hermes/function-non-strict.js + if (e.message === 'Restricted in strict mode') { + FunctionInstance[prop] = accessor; + } + } +}); + export const isAccessorPermit = permit => { return permit === getter || permit === accessor; }; From 031bed47e1d3daec6769c5f73ec5e8989858f946 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:44:48 +0000 Subject: [PATCH 2/3] refactor(ses): document removeUnpermittedIntrinsics now fixed in Static Hermes Ref https://github.com/facebook/hermes/issues/1582 Ref https://github.com/facebook/hermes/commit/bb90b33ac0bc22cdd35eae593de96faa6376437a --- packages/ses/src/permits.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ses/src/permits.js b/packages/ses/src/permits.js index 13432ad689..0fc5616f8f 100644 --- a/packages/ses/src/permits.js +++ b/packages/ses/src/permits.js @@ -310,6 +310,7 @@ arrayForEach(getOwnPropertyNames(strict), prop => { } catch (e) { // https://github.com/facebook/hermes/blob/main/test/hermes/function-non-strict.js if (e.message === 'Restricted in strict mode') { + // Fixed in Static Hermes: https://github.com/facebook/hermes/issues/1582 FunctionInstance[prop] = accessor; } } From fb31acad52938f6ca4e66e959ada82facea62e93 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:27:01 +0000 Subject: [PATCH 3/3] feat(ses): restrict dynamic permit on Hermes Co-authored-by: Mark S. Miller --- packages/ses/src/permits.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/ses/src/permits.js b/packages/ses/src/permits.js index 0fc5616f8f..283d861c34 100644 --- a/packages/ses/src/permits.js +++ b/packages/ses/src/permits.js @@ -1,7 +1,7 @@ /* eslint-disable no-restricted-globals */ /* eslint max-lines: 0 */ -import { arrayPush, getOwnPropertyNames, arrayForEach } from './commons.js'; +import { arrayPush, arrayForEach } from './commons.js'; /** @import {GenericErrorConstructor} from '../types.js' */ @@ -304,7 +304,8 @@ const strict = function () { 'use strict'; }; -arrayForEach(getOwnPropertyNames(strict), prop => { +// TODO Remove this once we no longer support the Hermes that needed this. +arrayForEach(['caller', 'arguments'], prop => { try { strict[prop]; } catch (e) {