HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Safely running untrusted Haskell code

Categories: How to

Obviously, don't run code in the IO monad, just show pure results (or possibly make your own monad that is a restricted subset of IO). But it's a lot more complicated than that...

Contents

1 Verifying safety : lambdabot's approach

Since 2004, lambdabot has executed arbitrary strings of Haskell provided by user's of various IRC channels, in particular, the Haskell channel. In order to do this, a particular security policy is required. The policy, and its implementation, is described here.

1.1 The policy

Only allow execution of pure Haskell expressions.

1.2 The implementation

The evaluator is essentially a function, eval :: String -> IO
String
, which takes a random Haskell string, verifies it, compiles it, and evaluates the result, returning a String representing the result, back over the network.

This function is implemented as two separate processes:

The driver reads a String from the network, and then subjects it to a simple test:

If the string parses as a Haskell 98 expression, the 'runplugs' process is then forked to evaluate the string, and the following checks are put in place:

A few other niceties are provided:

2 Exploits

A variety of interesting exploits have been found, or thought of, over the years. Those we remember are listed below:

3 Template Haskell

We believe that Template Haskell can be made safe for users by hiding runIO and reify.

4 See also

Retrieved from "http://www.haskell.org/haskellwiki/Safely_running_untrusted_Haskell_code"

This page has been accessed 3,265 times. This page was last modified 14:29, 12 June 2008. Recent content is available under a simple permissive license.