In a previous question I figured out how to eliminate unwanted global variables from the repl context. However, I figured out that the repl automatically has access to ALL internal node modules without the use of require. I have no idea how to disable this. I even tried overriding the module variables in the repl itself and it doesn't work.
> fs = "test";
> fs
It still displays fs original value. This is very unfortunate because I'm trying to expose a public repl but it gives them access to the entire server.
Any ideas?
As you said, the REPL has access to core modules.
(however, after checking, I am able to override them with node 0.10.20, so there should be a solution)
A better way would be to just override
repl._builtinLibsbefore creating a repl instance.Also, it's fairly trivial to white-list repl commands if you don't want to expose commands like
.saveor.load.Note: Arrays don't normally have a
containsmethod so I added one.If you want to remove variables from the repl instance's global scope see this question.
You can easily crash the whole server
Errors that happen in async callbacks are not caught by the REPL and bring down the node.js instance.
You can block the server
Your best bet would be to code your own REPL in a separate process with child_process, readline and vm. Here's a starting point:
The master:
and the separate process for the repl: