Safe-ish

NOT FOR PRODUCTION USE

Safe-ish is an experimental, minimally restrictive sandbox for BEAM modules that examines and rejects BEAM bytecode at load time containing instructions that could cause side effects such as:

You can provide an optional whitelist of modules, functions and language features that the loaded module is allowed to use.

Use

You can call:

All the above functions take a second optional whitelist argument of calls and language features to allow. The following list entries are allowed:

The return value for all functions is either {:ok, Module} or {:error, ["reason 1", "reason 2", ...]}

Example

> Safeish.load_file("CallFileRead.beam")
{:error, CallFileRead, ["Elixir.File.read/1 not whitelisted"]}
> Safeish.load_file("CallFileRead.beam", [{File, read, 1}])
{:ok, CallFileRead}
> CallFileRead.somefunc()

Installation

If available in Hex, the package can be installed by adding safeish to your list of dependencies in mix.exs:

def deps do
  [
    {:safeish, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/safeish.