Safe Haskell.

Making types truthful since 2011.

Safe Haskell is a new extension to the Haskell language that is implemented in GHC. It allows for unsafe code to be securely included into a trusted code base by restricting what features of Haskell the code is allowed to access. Intuitively it makes it so 'types don't lie'. Safe Haskell itself is aimed to be as minimal as possible to encourage broad adoption by the Haskell community. It provides strong enough guarantees about compiled Haskell code for more advance secure systems to be built on top of Haskell, using techniques such as information flow control security or encrypted computations. These techniques combined with Safe Haskell make Haskell a great language for building reliable, secure multi-party systems today. Particularly relevant with the growing power of web applications and the platform nature of many web sites.

How to use

  1. Safe Haskell is included with GHC since version 7.2. However, it is considered production quality since version 7.4 onwards.

  2. Read the GHC user guide on Safe Haskell

Users of Safe Haskell

GHC.IO

Source code Try Out!

GHC.IO is an online version of the GHC Haskell interactive interpreter (REPL), ghci. It safely executes arbitrary Haskell code entered over the network using a monad (and Safe Haskell of course) to sandbox the code. That is, instead of executing all user entered statements in the IO monad as usual, they are executed in a restricted IO monad of the admin's choosing.

The entire security policy is:
module GHC.GHCi ( GHCiSandboxIO(..), RIO(), putStrLn, putStr ) where

newtype RIO a = UnsafeRIO { rio :: IO a }

instance Monad RIO where
    return a = UnsafeRIO (return a)
    (>>=) k f = UnsafeRIO (rio k >>= rio . f)

instance GHCiSandboxIO RIO where
    ghciStepIO = rio

putStrLn :: String -> RIO ()
putStrLn s = UnsafeRIO (hPutStrLn stdout s)

putStr :: String -> RIO ()
putStr s = UnsafeRIO (hPutStr stdout s)

GitStart

Source code Try Out!

GitStar is a social source code management platform built using the new Hails web framework. GitStar provides your traditional web-based code hosting site with a twist: Instead of a single codebase, GitStar is composed of many applications, written by different people, safely operating on your data. Take a look at the /scs/hails project: the code viewer and wiki are "third-party untrusted" apps! Hails gives you server-side guarantees, but to prevent leaks from your browser you need to install our chrome extension.

Publications & presentations

More information

Team