-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that JavaScript code accessing process.env
doesn't immediatly crash the VM
#902
base: master
Are you sure you want to change the base?
Conversation
Oh, forgot to ping @lugehorsam as per his request 🙂 |
Ping @lugehorsam , I would really like to pull this through and possibly investigate whether even the |
I want this in master |
Hey @MarcusRiemer we are currently evaluating whether this change will conflict with our goal of the JS runtime being entirely sandboxed. |
Oh, actually I meant that it would be reasonable to support some of NodeJS APIs at some point ha-ha |
Fair enough, I can see the sandboxing argument. I would argue that the exact same data is already exposed via |
@MarcusRiemer - in addition to what Luke mentioned, this PR will open up more confusion on what Node compat exists in Nakama, and what Node libraries can be used. Additionally, our official recommendation for reading env variables (even in Go and Lua) would be to pass through the data via -runtime.env config/command-line flags. |
I'm totally on board with this recommendation for code specifically written for Nakama, but most code isn't. And is that confusion necessarily "bad", as long as the compatibility increases over time? I mean technically it's also bad right now because the Nakama documentation doesn't really give much indication about the available JavaScript or node.js features in a structured way. From my PoV it would be great to have as much of the node.js ecosystem readily available as possible. And I think that a tiny amount of node.js compatability (like supporting |
@MarcusRiemer How much of the process surface area would you determine to be a "tiny amount" with a huge impact? I think part of the challenge we have is that it's a slippery slope. The surface area of the process object as an example is huge: https://nodejs.org/api/process.html Where would we draw the line? |
I would draw the line with two goalposts:
Measuring the impact could be done by sampling popular packages, throwing their source code at nakama and see what crashes. The next thing on my list would be All that being said: I do get the hesitation about putting this into the go-core. Thankfully both of these issues (
I personally would still prefer to do this in the core and to later on also enable things like |
Ping @novabyte & @lugehorsam 🙂 |
As discussed on the forums: This is a very barebones "solution" to deal with JavaScript libraries that expect to read
process.env
. The related pull request for goja is dop251/goja_nodejs#33On a technical level this pulls in goja_nodejs as another dependency and enables the
process
support. So this common pattern to check whether code is run in a production enviroment will sort of work in goja as well. I didn't manage to run the unit tests locally, but locally everything worked fine with the following snippet:If I called this using
NODE_ENV=production ./nakama --runtime.js_entrypoint "./runtime-test.js"
I got the production log, otherwise the other log. Preliminary tests show that this addition allows me to get rid of a rollup plugin that rewrites these kind of checks.