talira

HtmlSanitizeEx

HTML sanitizer for Elixir that strips or allow-lists tags to stop XSS

open sourceMITfree

HtmlSanitizeEx (the html_sanitize_ex package) is an HTML sanitizer written in Elixir that lets a web app include HTML written by third parties while protecting against cross-site scripting. It parses an HTML string and, depending on the scrubber, strips every tag or keeps only allowed elements and attributes. Built-in scrubbers cover plain text, basic HTML, HTML5 and Markdown-generated HTML, and you can define your own scrubber that allows only the tags, attributes and URI schemes you need. Its only dependency is mochiweb, which it uses to parse HTML.

Problems it solves

  • let users post HTML in my Phoenix app without opening an XSS hole
  • strip all HTML tags from a string in Elixir
  • allow only links and paragraphs in user comments in Elixir

Features

  • strip_tags, basic_html, html5 and markdown_html scrubbers
  • custom scrubbers that allow only chosen tags, attributes and URI schemes
  • removes CDATA sections and comments in custom scrubbers
  • one dependency: mochiweb

Limitations

  • Its README says to check that a built-in scrubber does what you expect before you use or extend it.1