Live data from Hacker News

JavaScript engines zoo – Compare every JavaScript engine

zoo.js.org

51–60 of 97 posts

Re: JavaScript engines zoo – Compare every JavaScript engine

#51
post #46

Earlier quoted context omitted.

What's wrong with V8? You could also look at GraalJS. It's shipped as part of the Oracle Database, there's a security team, patching process etc. It's used in production by Amazon amongst others. It's got flexible sandbox features too. https://www.graalvm.org/latest/reference-manual/embed-langua... The way it's written is good for security as well: https://medium.com/graalvm/writing-truly-memory-safe-jit-com... Discl…

The challenge with V8 is finding a wrapper for it that doesn't come with a big warning NOT to use it as a sandbox for untrusted code - here's the workerd one https://github.com/cloudflare/workerd?tab=readme-ov-file#war... and here's the PyMiniRacer section: https://bpcreech.com/PyMiniRacer/architecture/#security-goal... I looked at GraalVM but was put off by the licensing situation: https://www.graalvm.org/22.3/refer…

Licensing has changed since that release. You can use the EE for free, both for personal and commercial use cases:

https://www.graalvm.org/latest/introduction/#licensing-and-s...

> Oracle GraalVM is licensed under GraalVM Free Terms and Conditions (GFTC) including License for Early Adopter Versions. Subject to the conditions in the license, including the License for Early Adopter Versions, the GFTC is intended to permit use by any user including commercial and production use.

It has all the sandboxing features you might want. I don't know if the disclaimers on the other engines changes much, open source software always disclaims all liability. Nobody will stand behind something security sensitive unless it's commercial because otherwise there's no way to pay for the security team it requires.

Re: JavaScript engines zoo – Compare every JavaScript engine

#52
post #41

All these JavaScript engines and it's still remarkably hard to find a robust solution for executing JavaScript from untrusted sources inside my own server-side applications. Every time I look I find repos that look promising at first but are either unmaintained or have a team or just one or two maintainers running them as a side project. I want my sandbox to be backed by a large, well funded security team working for…

Not a silver bullet, but did you look into isolated-vm? https://github.com/laverdet/isolated-vm But generally, I think best bet is to offload such things to e.g. Lambda per tenant.

The README says it's in maintenance mode and the single author doesn't have time to dedicate to the project.

Re: JavaScript engines zoo – Compare every JavaScript engine

#53
post #50
post #41

All these JavaScript engines and it's still remarkably hard to find a robust solution for executing JavaScript from untrusted sources inside my own server-side applications. Every time I look I find repos that look promising at first but are either unmaintained or have a team or just one or two maintainers running them as a side project. I want my sandbox to be backed by a large, well funded security team working for…

https://github.com/bellard/mquickjs Featured recently on HN.

Yeah that (and full QuickJS) running inside WebAssembly do appear to be my best options. Here's my experiment running that one in WASM: https://github.com/simonw/research/tree/main/mquickjs-sandbo...

Re: JavaScript engines zoo – Compare every JavaScript engine

#54
post #41

All these JavaScript engines and it's still remarkably hard to find a robust solution for executing JavaScript from untrusted sources inside my own server-side applications. Every time I look I find repos that look promising at first but are either unmaintained or have a team or just one or two maintainers running them as a side project. I want my sandbox to be backed by a large, well funded security team working for…

Put them in a container or VM? Security benefits from layering: engine/runtime is one layer, container/VM is another - an attacker would need two independent high-value exploits to breach both of them.

High budget is no guarantee for absence of critical bugs in an engine, maybe even somewhat opposite - on a big team the incentives are aligned with shipping more features (since nobody gets promoted for maintenance, especially at Google) -> increasing complexity -> increasing bug surface.

If speed is less important and you can live without JIT, that expands your options dramatically and eliminates a large class of bugs. You could take a lightweight engine and compile it to a memory-safe runtime, that'd give you yet another security layer for peace of mind. Several projects did such ports to Wasm/JS/Go - for example your browser likely runs QuickJS to interpret JavaScript inside .pdf (https://github.com/mozilla/pdf.js.quickjs)

Re: JavaScript engines zoo – Compare every JavaScript engine

#55

You can see when JIT is disabled, the upcoming Static Hermes (Hermes V1) engine from Meta, built specifically for React Native, outperforms both V8 and JSCore on Apple Silicon It'll be interesting to see how much it will affect React Native apps as it gets more and more optimized for this use case

React Native continues to be one of the best technology bets I’ve ever made. At one point I really thought that Flutter would outclass it but typical Google project stuff has really put a damper on it from all I can see. It’s not better than native apps, but as far as cross platform GuIs go it’s still very very good

Flutter and KMM are actually very good and better to use than the debacle that React Native can be. But they’re worlds behind in community support, and React Native became the ‘kitchen sink’ that works for most needs.

As a React Native developer for, what, 6 years, I don’t have much positivity left to offer. Bug reports to the core team that went nowhere, the Android crash on remote images without dimensions, all the work offloaded to Expo, etc.

Google couldn’t really done better, maybe Flutter should’ve become independent after the initial release.

Re: JavaScript engines zoo – Compare every JavaScript engine

#56

Is there any benchmarks between engines that record memory usage? How many of these engines are chasing benchmarks at the cost of increased memory usage?

I captured max RSS size while running benchmarks as a rough approximation, but it's not exposed anywhere. If you go to the repo, you can run `./bench/compare -f rss_mb -lT bench/amd64/*.json` to see a table in the terminal. No big surprises there, Java engines (Rhino, Nashorn, GraalJS) are most memory-hungry.

Re: JavaScript engines zoo – Compare every JavaScript engine

#57
I got a question for everyone: as a web user, have you been affected by performance limitations of a particular JS engine? Have you switched browsers b/c of JS speed?

My n=1 as a long time Firefox user is that performance is a non-issue (for the sites I frequent). I’m much more likely to switch browsers because of annoying bugs, like crashes due to FF installed as a snap.

It honestly is pretty surprising, given that JS runtime runs website code single-threaded.

Re: JavaScript engines zoo – Compare every JavaScript engine

#58
post #41

All these JavaScript engines and it's still remarkably hard to find a robust solution for executing JavaScript from untrusted sources inside my own server-side applications. Every time I look I find repos that look promising at first but are either unmaintained or have a team or just one or two maintainers running them as a side project. I want my sandbox to be backed by a large, well funded security team working for…

To add some color to "workerd is not a hardened sandbox":

workerd does not include any sandboxing layers other than V8 itself. If someone has a V8 zero-day exploit, they can break out of the sandbox.

But putting aside zero-day exploits for a moment, workerd is designed to be a sandbox. That is, applications by default have access to nothing except what you give them. There is only one default-on type of access: public internet access (covering public IPs only). You can disable this by overriding `globalOutbound` in the config (with which you can either intercept internet requests, or just block them).

This is pretty different from e.g. Node, which starts from the assumption that apps should have permission to run arbitrary native code, limited only by the permissions of the user account under which Node is running.

Some other runtimes advertise various forms of permissions, but workerd is the only one I know of where this is the core intended use case, and where all permissions (other than optionally public internet access, as mentioned) must be granted via capability-based security.

Unfortunately, JavaScript engines are complicated, which means they tend to have bugs, and these bugs are often exploitable to escape the sandbox. This is not just true of V8, it's true of all of them; any that claims otherwise is naive. Cloudflare in production has a multi-layer security model to mitigate this, but our model involves a lot of, shall we say, active management which can't easily be packaged up into an open source product.

With all that said, not all threat models require you to worry about such zero-day exploits, and you need to think about risk/benefit tradeoffs. We obviously have to worry about zero-days at Cloudflare since anyone can just upload code to us and run it. But if you're not literally accepting code directly from anonymous internet users then the risk may be a lot lower, and the overall security benefit of fine-grained sandboxing may be worth the increased exposure to zero-days.

Re: JavaScript engines zoo – Compare every JavaScript engine

#59
post #57

I got a question for everyone: as a web user , have you been affected by performance limitations of a particular JS engine? Have you switched browsers b/c of JS speed? My n=1 as a long time Firefox user is that performance is a non-issue (for the sites I frequent). I’m much more likely to switch browsers because of annoying bugs, like crashes due to FF installed as a snap. It honestly is pretty surprising, given that…

No, speed / performance of JavaScript has never, in my entire history of web use, been a driving factor in picking a browser - there may be one-offs here and there where I’m annoyed I have to switch to a different browser for a few minutes due to feature support or extension availability - but I can’t remember thinking “boy I wish JavaScript didn’t run so slow”

Re: JavaScript engines zoo – Compare every JavaScript engine

#60
post #58
post #41

All these JavaScript engines and it's still remarkably hard to find a robust solution for executing JavaScript from untrusted sources inside my own server-side applications. Every time I look I find repos that look promising at first but are either unmaintained or have a team or just one or two maintainers running them as a side project. I want my sandbox to be backed by a large, well funded security team working for…

To add some color to "workerd is not a hardened sandbox": workerd does not include any sandboxing layers other than V8 itself. If someone has a V8 zero-day exploit, they can break out of the sandbox. But putting aside zero-day exploits for a moment, workerd is designed to be a sandbox. That is, applications by default have access to nothing except what you give them. There is only one default-on type of access: publi…

Right - I trust workerd in the context of Cloudflare because I know it has a team of people who's job it is to keep it secure who are on-call 24/7.

The problem I have is that I'm just one person and I don't want to be on call 24/7 ready to react to sandbox escapes, so I'm hoping I can find a solution that someone else built where they are willing to say "this is safe: you can feed in a string of untrusted JavaScript and we are confident it won't break out again".

I think I might be able to get there via WebAssembly (e.g. with QuickJS or MicroQuickJS compiled to WASM) because the whole point of WebAssembly is to solve this one problem.

> But if you're not literally accepting code directly from anonymous internet users then the risk may be a lot lower

That's the problem: this is exactly what I want to be able to do!

I want to build extension systems for my own apps such that users can run their own code or paste in code written by other people and have it execute safely. Similar to Shopify Functions: https://shopify.dev/docs/apps/build/functions

I think the value unlocked by this kind of extension mechanism is ready to skyrocket, because users can use LLMs to help write that code for them.

Post reply on HN