NMandelbrot : running arbitrary code on client
Tags: development, programming, security, cloud
Published: 2018-04-20 10:52:05

---
title: NMandelbrot : running arbitrary code on client
published: true
tags: development,programming,security,cloud
canonical_url: https://craignicol.wordpress.com/2018/04/20/nmandelbrot-running-arbitrary-code-on-client/
---

As part of my grand plan for [map-reduce in JavaScript](https://craignicol.wordpress.com/2014/07/29/the-node-js-mandelbrot-set/) and zero-install distributed computing, I had to think about how to gain user trust in a security context where we [don’t trust the server](https://craignicol.wordpress.com/2014/05/27/the-three-rules-of-network-security/). I couldn’t come up with a good answer.

Since then, we’ve seen stories of [malicious JavaScript](https://craignicol.wordpress.com/2015/05/25/nmandelbrot-clients-gaming-the-system/) [installed](https://craignicol.wordpress.com/2015/03/17/is-your-cpu-time-there-to-be-stolen/) to [mine](http://www.forbes.com/sites/kashmirhill/2013/11/19/brilliant-but-evil-gaming-company-turned-players-computers-into-unwitting-bitcoin-mining-slaves/) [cryptocurrencies](https://cloudblogs.microsoft.com/microsoftsecure/2018/03/13/invisible-resource-thieves-the-increasing-threat-of-cryptocurrency-miners/) , we know that [JavaScript can be exploited to read kernel memory, including passwords, on the client](https://isc.sans.edu/forums/diary/Meltdown+and+Spectre+clearing+up+the+confusion/23197/), and I suspect we’ll see a lot more restrictions on what JavaScript is allowed to do – although as the Spectre exploit is fundamentally an array read, it’s going to be a complex fix at multiple levels.

I had ideas about how to sandbox the client JavaScript (I was looking at Python’s virtualenv and Docker containers to isolate code, as well as locking them into service workers which already have a vastly more limited API), but that relies on the browser and OS maintaining separation, and if VMs can’t [maintain](https://www.techrepublic.com/article/10-new-vm-escape-vulnerabilities-discovered-in-virtualbox/) [separation](https://threatpost.com/vmware-patches-pwn2own-vm-escape-vulnerabilities/124629/) with their levels of isolation, it’s not an easy job for browser developers, or anyone running on their platform.

I also wondered if the clients should be written in a [functional language that transpiled to JavaScript](https://fable.io), to have language level enforcement of immutability and safety checks. And of course, because [a functional style and API](https://medium.com/dailyjs/functional-js-with-es6-recursive-patterns-b7d0813ef9e3) provides a simpler context to reason about map-reduce, by avoiding any implicit shared context.

[Do you allow someone else’s JavaScript on your site](https://www.zdnet.com/article/uk-government-websites-ico-hijacked-by-cryptocurrency-mining-malware/), whether a library, or a tracking script, or random ads from Russia, Korea, botnets and script kiddies? How do you keep your customers safe? And how do you isolate processes you trust from processes that deal with the outside world and users? JavaScript will be more secure in the future, and the research is fascinating ([JavaScript Zero: real JavaScript, and zero side-channel attacks](https://blog.acolyer.org/2018/03/13/javascript-zero-real-javascript-and-zero-side-channel-attacks/)) but can you afford to wait?

Meltdown and Spectre shouldn’t change any of this. But now is a good time to think about it. Make 2018 the year you become paranoid about users, 3rd parties and other threats. The year is still young, but the exploits are piling up.