@@ -102,6 +102,7 @@ const safeHarden = makeHardener();
102
102
103
103
const assertDirectEvalAvailable = ( ) => {
104
104
let allowed = false ;
105
+ let evaluatorsBlocked = false ;
105
106
try {
106
107
allowed = FERAL_FUNCTION (
107
108
'eval' ,
@@ -122,12 +123,13 @@ const assertDirectEvalAvailable = () => {
122
123
// We reach here if eval is outright forbidden by a Content Security Policy.
123
124
// We allow this for SES usage that delegates the responsibility to isolate
124
125
// guest code to production code generation.
125
- allowed = true ;
126
+ evaluatorsBlocked = true ;
126
127
}
127
- if ( ! allowed ) {
128
+ if ( ! allowed && ! evaluatorsBlocked ) {
128
129
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
129
130
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'?` ,
131
133
) ;
132
134
}
133
135
} ;
@@ -152,11 +154,11 @@ export const repairIntrinsics = (options = {}) => {
152
154
// The `stackFiltering` is not a safety issue. Rather it is a tradeoff
153
155
// between relevance and completeness of the stack frames shown on the
154
156
// 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
156
158
// `stackFrameFiltering` to`'concise'` limits the display to the stack frame
157
159
// information most likely to be relevant, eliminating distracting frames
158
160
// 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
160
162
// is useful. See
161
163
// [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options)
162
164
// for an explanation.
@@ -189,6 +191,9 @@ export const repairIntrinsics = (options = {}) => {
189
191
/** @param {string } debugName */
190
192
debugName => debugName !== '' ,
191
193
) ,
194
+ legacyHermesTaming = /** @type { 'safe' | 'unsafe' } */ (
195
+ getenv ( 'LOCKDOWN_LEGACY_HERMES_TAMING' , 'safe' )
196
+ ) ,
192
197
legacyRegeneratorRuntimeTaming = getenv (
193
198
'LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING' ,
194
199
'safe' ,
@@ -199,6 +204,10 @@ export const repairIntrinsics = (options = {}) => {
199
204
...extraOptions
200
205
} = options ;
201
206
207
+ legacyHermesTaming === 'safe' ||
208
+ legacyHermesTaming === 'unsafe' ||
209
+ Fail `lockdown(): non supported option legacyHermesTaming: ${ q ( legacyHermesTaming ) } ` ;
210
+
202
211
legacyRegeneratorRuntimeTaming === 'safe' ||
203
212
legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
204
213
Fail `lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${ q ( legacyRegeneratorRuntimeTaming ) } ` ;
@@ -218,13 +227,11 @@ export const repairIntrinsics = (options = {}) => {
218
227
const { warn } = reporter ;
219
228
220
229
if ( dateTaming !== undefined ) {
221
- // eslint-disable-next-line no-console
222
230
warn (
223
231
`SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.` ,
224
232
) ;
225
233
}
226
234
if ( mathTaming !== undefined ) {
227
- // eslint-disable-next-line no-console
228
235
warn (
229
236
`SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.` ,
230
237
) ;
@@ -242,7 +249,14 @@ export const repairIntrinsics = (options = {}) => {
242
249
// trace retained:
243
250
priorRepairIntrinsics . stack ;
244
251
245
- assertDirectEvalAvailable ( ) ;
252
+ if ( legacyHermesTaming === 'safe' ) {
253
+ assertDirectEvalAvailable ( ) ;
254
+ } else if ( legacyHermesTaming === 'unsafe' ) {
255
+ // See https://github.com/facebook/hermes/issues/957
256
+ warn (
257
+ `SES initializing with an unoriginal intrinsic 'eval', not suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)` ,
258
+ ) ;
259
+ }
246
260
247
261
/**
248
262
* Because of packagers and bundlers, etc, multiple invocations of lockdown
@@ -408,6 +422,12 @@ export const repairIntrinsics = (options = {}) => {
408
422
markVirtualizedNativeFunction,
409
423
} ) ;
410
424
425
+ if ( legacyHermesTaming === 'unsafe' ) {
426
+ globalThis . testCompartmentHooks = undefined ;
427
+ // @ts -ignore Compartment does exist on globalThis
428
+ delete globalThis . Compartment ;
429
+ }
430
+
411
431
if ( evalTaming === 'noEval' ) {
412
432
setGlobalObjectEvaluators (
413
433
globalThis ,
@@ -420,6 +440,7 @@ export const repairIntrinsics = (options = {}) => {
420
440
globalThis ,
421
441
safeEvaluate ,
422
442
markVirtualizedNativeFunction ,
443
+ legacyHermesTaming ,
423
444
) ;
424
445
} else if ( evalTaming === 'unsafeEval' ) {
425
446
// Leave eval function and Function constructor of the initial compartment in-tact.
0 commit comments