In my Haskell application I implemented the following mechanism for passing sensitive information to the binary (without resorting to CLI parameters):
- I use a
TemplateHaskell
mechanism for reading environment variables at compile time:
{-# LANGUAGE TemplateHaskell #-}
...
import Language.Haskell.TH.Env
...
myPrecious :: String
myPrecious = fromMaybe "" $$(envQ "MY_PRECIOUS")
...
- When compiling, I pass the relevant environment variable like so:
MY_PRECIOUS=<secret> stack build
and it then gets bound tomyPrecious
on the Haskell side - The resulting binary has the value of
MY_PRECIOUS
compiled in, so it won't be visible from the operating system level (e.g. viaps aux
)
Trouble is, I can now open that binary in a text editor or create a memory dump (e.g. with GDB) and with a little determination dig up the secret, especially if I know the context in which it is being used - I'm assuming that some malicious actor might have obtained access to the source code. So I've been wondering, is there any way to force GHC to produce a more obfuscated/garbled binary, in which such values would not be readily visible. I'm aware that no such protection scheme can be bulletproof, but I'm looking for a way to make the intruder's task harder.