Also, I don't know what of this you can do in Python, but the type system in Haskell lets you build tools so that the same program can simultaneously read local data unrestricted, transmit data to any website unrestricted, and still be
provably incapable of actually sending out any of your private information to a 3rd party. You can even give it the ability to create files in essentially arbitrary locations quite safely. Basically, you have a Client monad and a Server monad, and runClient and runServer functions, which take types Client () and Server (), and executes them, but in such a way that information cannot escape from them.
Overly simple example, not even using any monadic properties because I'm lazy and sleepy:
- Code: Select all
module Buh where
import Nar
main = runNar $ evil `andThen` fiendish (++"!") `andThen` moreEvil
- Code: Select all
module Nar (runNar, evil, moreEvil, andThen, fiendish) where
newtype Nar a = Nar {run :: IO a}
runNar a = run a :: IO ()
evil = Nar $ readFile "secretdata.txt"
fiendish fn = Nar . (>>= return . fn) . run
moreEvil = Nar . \x -> getLine >>= flip writeFile x
andThen a b = Nar $ run a >>= (run . b)
There's nothing module "Buh" can do with the information obtained from evil except for applying pure functions with fiendish, and piping it to moreEvil, which will write the data anywhere
the user (well, technically, the program input, in a more complicated example you could make it explicitly a user prompt) tells it to. The program doesn't even have any say in where to put it.
We're ignoring here that Prelude imports readFile and writeFile, which are the functions we're actually trying to hide away securely, but that's not entirely terrible because we can simply check for their use.
If the module contains no readFile or writeFile actions, and imports only Nar, then we have pretty much shown it to be secure as far as the actions hidden by Nar are concerned. If all of the actions you want your script to perform are properly wrapped up like so, and you prove the library secure, then a simple mechanical check is enough to ensure the script is safe not just to interpret in a restricted environment, but compile and run right on the hardware.