Skip to content

Feature Request: local eval for SES (Secure EcmaScript) support #957

@leotm

Description

@leotm

Problem

Hey there, Leo here from team LavaMoat and MetaMask 👋

i'm working with the folks at EndoJS bringing SES (formerly Agoric/SES) support to RN and metamask-mobile

which runs on JSC and V8, but not Hermes as we know

Excluded From Support

  • Local mode eval() (use and introduce local variables)
  • with statements
# RN: Android/iOS (Hermes) with SES
ERROR  TypeError: SES cannot initialize unless 'eval' is the original intrinsic 'eval',
suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL), js engine: hermes
# https://user-images.githubusercontent.com/1881059/232474795-666c83e9-53aa-4df0-a8cd-a5e45277392d.png
# https://user-images.githubusercontent.com/1881059/232477719-56c92715-b72d-4c5d-9756-a972cd88c6b1.png

stacktraces ^ from the SES lockdown shim (e.g. curl -O https://npmfs.com/download/ses/0.18.4/dist/lockdown.umd.js)
also importable via yarn add ses, but needing additional Metro and Babel config for .cjs

i note potentially supporting this feature's been discussed in the past (cc @kumavis) and past convo's

is this a feature you guys looking to make happen anytime soon?
or still only accepting community contributions

Solution

Describe the solution you'd like to happen: local eval() support 🙏
Or with statements support (can be split into separate ft req)

Alternatives considered

  • init SES without our original intrinsic eval
    • then we'd run into unsupported with statements
  • facebook/hermes community contribution: local eval()
  • facebook/hermes community contribution: with statements
  • couple further options we're exploring

Additional Context

SES

https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md

The SES Hardened JavaScript shim captures the eval function when it is initialized. The eval function it finds must be the original eval because SES uses its dynamic scope to implement its isolated eval.

If you see this error, something running before ses initialized, most likely another instance of ses, has replaced eval with something else.

React Native LavaMoat tracker

Hermes docs

hermesengine.dev/playground

# eval(1)

/tmp/hermes-input.js:1:1: warning: Direct call to eval(), but lexical scope is not supported.

Function<global>(1 params, 1 registers, 0 symbols):
Offset in debug table: source 0x0000, lexical 0x0000
    LoadConstUInt8    r0, 1
    DirectEval        r0, r0
    Ret               r0

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions