dealloc

dealloc

I’m writing an application in Elixir where users should be able to create templates (which later get rendered into HTML and then into PDF).
I’m currently working with EEx, however there’s two problems to tackle:

  • code execution (this one I know how to handle, since EEx can compile to a quoted expression which I can walk to detect unauthorized calls)
  • atom generation

The second one is more problematic, EEx generates atoms for the variables used in the template, and we all know that having users create atoms is a BAD idea.

I had submitted a PR (which will appear in 1.13) to allow me passing in a method that is called when creating atoms and instead output strings, however turns out that in the tokenization step EEx generates am atom and then returns it as a string (but the atom is created nonetheless).

The only way to avoid this would be passing in a parser_options to the tokenizer call which I think isn’t even public API (:elixir_tokenizer) so I’m guessing a PR to add options to that will be rejected (José if you’re reading this and I’m wrong let me know!).

Long story short, anyone have experience in this, suggestions or ideas? I’d want to have user supplied templates, at runtime to generate HTML.

EEx is currently problematic due to atoms being created while compiling.

EDIT: I’m currently on mobile but when I’m home I’ll link the exact code that causes problems along with some tests and examples :slight_smile:

EDIT 2: The exact line that’s generating atoms is https://github.com/elixir-lang/elixir/blob/master/lib/eex/lib/eex/tokenizer.ex#L73 if I could pass in a static_atoms_encoder option (see Code — Elixir v1.12.3) I could use EEx templates without it generating any atoms at all (I verified this with a locally modified EEx library).

Showing Posts 1 to 6

hauleth

hauleth

There is no way to make EEx safe. Instead you should use another template library that will not also be easier for users, but also will be more secure, for example:

dealloc

dealloc OP

This would be for an internal tool and the people using it would have experience with Elixir, so the EEx syntax would already be familiar. Honestly the only real problem I’m still facing is the generation of atoms and I’d really like to solve it if possible (without having an entire modified copy of the EEx source code in my application (even if that’s just 4-5 files).

Regardless I’ll definitely take a look at the libraries you linked, thanks a bunch!

derek-zhou

derek-zhou

There is no way to make any templating safe, not even markdown. However, you can sanitize the resulting html with [html_sanitize_ex | Hex]

Turned out I did not read the original post carefully. I was thinking about safe to embedding user content on your website and the post was talking about safe to run elixir flavored template in the application. Then I have no idea; it is not something I dare to try.

wanton7

wanton7

I’m quite sure markdown is safe if you disable its HTML support.

dealloc

dealloc OP

With Markdown the “unsafe” part is potential XSS attacks, but in this case the internal tool will just render the HTML in a headless browser (that doesn’t keep any state) to render a PDF.
The HTML here is not much of a security concern, but that’s just this specific case :slight_smile:

sb8244

sb8244

Author of Real-Time Phoenix

my experiences with solid have been very good. It has been able to do everything that I want so far, including customizing some of the available template functions.

Giving users direct access to eex is probably not the best idea? Solid is a liquid template implementation, which was designed to run code from potentially hostile users.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews