@@ -102,6 +102,7 @@ const safeHarden = makeHardener();
102102
103103const assertDirectEvalAvailable = ( ) => {
104104 let allowed = false ;
105+ let evaluatorsBlocked = false ;
105106 try {
106107 allowed = FERAL_FUNCTION (
107108 'eval' ,
@@ -122,12 +123,13 @@ const assertDirectEvalAvailable = () => {
122123 // We reach here if eval is outright forbidden by a Content Security Policy.
123124 // We allow this for SES usage that delegates the responsibility to isolate
124125 // guest code to production code generation.
125- allowed = true ;
126+ evaluatorsBlocked = true ;
126127 }
127- if ( ! allowed ) {
128+ if ( ! allowed && ! evaluatorsBlocked ) {
128129 // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
129130 throw TypeError (
130- `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)` ,
131+ `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)
132+ Did you mean legacyHermesTaming: 'unsafe'?` ,
131133 ) ;
132134 }
133135} ;
@@ -152,11 +154,11 @@ export const repairIntrinsics = (options = {}) => {
152154 // The `stackFiltering` is not a safety issue. Rather it is a tradeoff
153155 // between relevance and completeness of the stack frames shown on the
154156 // console. Setting`stackFiltering` to `'verbose'` applies no filters, providing
155- // the raw stack frames that can be quite versbose . Setting
157+ // the raw stack frames that can be quite verbose . Setting
156158 // `stackFrameFiltering` to`'concise'` limits the display to the stack frame
157159 // information most likely to be relevant, eliminating distracting frames
158160 // such as those from the infrastructure. However, the bug you're trying to
159- // track down might be in the infrastrure , in which case the `'verbose'` setting
161+ // track down might be in the infrastructure , in which case the `'verbose'` setting
160162 // is useful. See
161163 // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options)
162164 // for an explanation.
@@ -189,6 +191,9 @@ export const repairIntrinsics = (options = {}) => {
189191 /** @param {string } debugName */
190192 debugName => debugName !== '' ,
191193 ) ,
194+ legacyHermesTaming = /** @type { 'safe' | 'unsafe' } */ (
195+ getenv ( 'LOCKDOWN_LEGACY_HERMES_TAMING' , 'safe' )
196+ ) ,
192197 legacyRegeneratorRuntimeTaming = getenv (
193198 'LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING' ,
194199 'safe' ,
@@ -199,6 +204,10 @@ export const repairIntrinsics = (options = {}) => {
199204 ...extraOptions
200205 } = options ;
201206
207+ legacyHermesTaming === 'safe' ||
208+ legacyHermesTaming === 'unsafe' ||
209+ Fail `lockdown(): non supported option legacyHermesTaming: ${ q ( legacyHermesTaming ) } ` ;
210+
202211 legacyRegeneratorRuntimeTaming === 'safe' ||
203212 legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
204213 Fail `lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${ q ( legacyRegeneratorRuntimeTaming ) } ` ;
@@ -218,13 +227,11 @@ export const repairIntrinsics = (options = {}) => {
218227 const { warn } = reporter ;
219228
220229 if ( dateTaming !== undefined ) {
221- // eslint-disable-next-line no-console
222230 warn (
223231 `SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.` ,
224232 ) ;
225233 }
226234 if ( mathTaming !== undefined ) {
227- // eslint-disable-next-line no-console
228235 warn (
229236 `SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.` ,
230237 ) ;
@@ -242,7 +249,13 @@ export const repairIntrinsics = (options = {}) => {
242249 // trace retained:
243250 priorRepairIntrinsics . stack ;
244251
245- assertDirectEvalAvailable ( ) ;
252+ if ( legacyHermesTaming === 'safe' ) {
253+ assertDirectEvalAvailable ( ) ;
254+ } else if ( legacyHermesTaming === 'unsafe' ) {
255+ warn (
256+ `SES initializing with an unoriginal intrinsic 'eval', not suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)` ,
257+ ) ;
258+ }
246259
247260 /**
248261 * Because of packagers and bundlers, etc, multiple invocations of lockdown
@@ -408,6 +421,12 @@ export const repairIntrinsics = (options = {}) => {
408421 markVirtualizedNativeFunction,
409422 } ) ;
410423
424+ if ( legacyHermesTaming === 'unsafe' ) {
425+ globalThis . testCompartmentHooks = undefined ;
426+ // @ts -ignore Compartment does exist on globalThis
427+ delete globalThis . Compartment ;
428+ }
429+
411430 if ( evalTaming === 'noEval' ) {
412431 setGlobalObjectEvaluators (
413432 globalThis ,
@@ -420,6 +439,7 @@ export const repairIntrinsics = (options = {}) => {
420439 globalThis ,
421440 safeEvaluate ,
422441 markVirtualizedNativeFunction ,
442+ legacyHermesTaming ,
423443 ) ;
424444 } else if ( evalTaming === 'unsafeEval' ) {
425445 // Leave eval function and Function constructor of the initial compartment in-tact.
0 commit comments