Utility.EExSafeEngine (Portico/Z v0.1.0)
Custom EEx
engine that only allows certain Elixir Kernel
constructs.
Security + Code Injection
The general idea here is that:
- We want folks to be able to do logic as well as field references in their HTML templates.
- Example:
<%= 1 + 1 %>
or<%= if x, do: "y" %>
- Example:
- We do not want folks to be able to make system calls, mess with databases, or anything else.
- Example:
<%= File.rm "/all_your_data" %>
- Example:
- Default EEx templates are designed mostly to be used from a compiled standpoint with safe data references. Unknown user data would be a huge security hazard because code injection is 100% possible.
- We can get rid of the bad parts of code injection by simply disabling any Elixir or Erlang module name reference, and only allowing native operators like
+
,if/then
etc.
Module Exceptions
Currently functions from the following modules will be allowed because they're just so danged handy:
All other module / function calls, including Erlang modules (for example :sys
), will return "SYNTAX ERROR"
as the body text.
Link to this section Summary
Functions
Callback implementation for EEx.Engine.handle_begin/1
.
Callback implementation for EEx.Engine.handle_body/1
.
Callback implementation for EEx.Engine.handle_end/1
.
Callback implementation for EEx.Engine.handle_expr/3
.
Callback implementation for EEx.Engine.handle_text/3
.
Callback implementation for EEx.Engine.init/1
.
Make damned sure that no unacceptable module calls are possible from EEx templates.
Link to this section Functions
handle_begin(state)
Callback implementation for EEx.Engine.handle_begin/1
.
handle_body(state)
Callback implementation for EEx.Engine.handle_body/1
.
handle_end(state)
Callback implementation for EEx.Engine.handle_end/1
.
handle_expr(state, marker, expr)
Callback implementation for EEx.Engine.handle_expr/3
.
handle_text(state, meta, text)
Callback implementation for EEx.Engine.handle_text/3
.
init(opts)
Callback implementation for EEx.Engine.init/1
.
raise_on_module_calls(ast)
Make damned sure that no unacceptable module calls are possible from EEx templates.