csisnett

csisnett

How to render user inputted html safely with phoenix

Hi everybody!

I have a description field of a Project schema which I plan to edit with
a wysiwyg editor, so I wanted to save the string as html. I want to show the description html in the Project page by using the Phoenix raw function but I’m not sure if this is safe, especially as users would be able to edit their projects.

How can I make sure the html I render is safe?
If you know where I can learn more on sanitizing with phoenix it’d be of great help

Most Liked

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

Does the string have to be HTML? Can your WYSIWYG be a Markdown editor? If so, you can store the description as Markdown and parse it using something like Earmark.

If not, this might be helpful: GitHub - rrrene/html_sanitize_ex: HTML sanitizer for Elixir · GitHub

NobbZ

NobbZ

Well, some editors spit out markdown, others restructured text, some plain HTML. For those that don’t give you the HTML, you need to render the source into HTML.

Rendering it each time the contents is requested might hurt server performance, therefore prerendered version is often cached in the database.

seanmor5

seanmor5

Author of Genetic Algorithms in Elixir

You could use both (kind of like how this editor works) and use the markdown_html/1 function in the HTML Sanitizer package.

Last Post!

csisnett

csisnett

Oh I get it now, I’ll save it pre-rendered then :smiley:

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement