Skip to content
Prev 8937 / 12125 Next

[R-pkg-devel] Sanitize Input Code for a Shiny App

Bill,

the short answer is you can't limit anything at R level. Any attempts to create a list of "bad" commands are trivial to circumvent since you can compute on the language in R, so you can construct and call functions with trivial operations. Similarly, since R allows the loading of binary code the same applies for arbitrary code. So if you give users access to R, you should assume that is equivalent to allowing arbitrary code execution. Therefore all you can do is limit the resources and reach - as you pointed out using a container is a good idea so each session is only limited to a single container that goes away when the session ends. Similarly you can restrict main parts of R and the system to be read-only in the container.

In practice, that's why real analytic systems are about provenance rather than prevention. For example, in RCloud all code is first committed to a git repository outside of the container before it can be executed, so malicious users can do whatever they want, but they cannot hide the malicious code they used as the container cannot manipulate the history.

As for package installation - again, it's impossible to prevent it in general unless you make everything read-only which also prevents the users from doing meaningful work. So the real question what do you want to allow the user to do - why would you need to allow literal R code evaluation? The other alternative is to simply limit the interaction not allowing the user to submit arbitrary code, only tweak parameters or use GUI to select particular choices. Obviously, that is a lot easier to secure.

Cheers,
Simon