Siubaak / sval

A javascript interpreter written in javascript
https://jsbin.com/kehahiqono/edit?js,console
MIT License
379 stars 50 forks source link

How safe is this interpreter? #64

Closed cosbgn closed 4 years ago

cosbgn commented 4 years ago

I need to run some external code on my app. I'm mostly concerned that this external code can access localstorage and cookies. Can the interpreter do that? Is there a way to disable certain APIs like localstorage, eval etc? Thank you!

Siubaak commented 4 years ago

Sval isn't a safe choice.

Of course you can disable certain global APIs by just overwriting it using import, for example, interpreter.import('localStorage', false).

However, external scripts can hack the prototype chain to "steal" the original one from host environment. It's nearly impossible to protest the prototype chain and also Sval has no protections on original prototype at all.