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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New

Other Trending Topics Top

mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews