9

I am developing a asp.net web app enabling users to submit F# code, which should be dynamically compiled and executed on the server. I was thinking of either hosting the F# compiler in the web app using the approach shown here: https://fsharp.github.io/FSharp.Compiler.Service/compiler.html Or use F# interactive: http://fsharp.github.io/FSharp.Compiler.Service/interactive.html

The idea would be to dynamically compile the F# code and then load it as an assembly in c# or have F# interactive interpret the code. However, my main concern is security and how to stop the end user from executing arbitrary code. Is there an easy way to restrict this? Thanks!

BigONotation
  • 4,406
  • 5
  • 43
  • 72
  • 2
    For small snippets, perhaps check out the implementation of the @FsiBot Twitter bot (https://github.com/mathias-brandewinder/fsibot). – Grundoon Apr 25 '16 at 15:53
  • Also, there's quite of a lot of discussion on doing this with C#. Different compiler, but many of the issues (such as security) are the same – Grundoon Apr 25 '16 at 16:01
  • Well the most important issue is security. What stops the user from wiping out the whole disk with a script? – BigONotation Apr 26 '16 at 00:02
  • 2
    One solution could be to dynamically compile the F# code using compiler services and then load the resulting assembly in a sandbox app domain as explained here: https://msdn.microsoft.com/en-us/library/bb763046(v=vs.110).aspx – BigONotation Apr 26 '16 at 00:31
  • See also http://stackoverflow.com/questions/1094478/what-is-a-net-application-domain – BigONotation Apr 26 '16 at 06:24

1 Answers1

1

This is an old question and things have considerably changed since it was asked. Now the Fable team have managed to run the F# compiler inside of a web-worker, removing the need to execute code on the server-side. This side-steps all of the security concerns around executing untrusted code.

  • You can try out the REPL here.
  • You can view the source-code here.
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245