ActionText stripping out iframe tag despite whitelisting them in Rails 6 application

Viewed 179

I'm using ActionText inside of a rails 6 application. I added custom attachments to Trix so that users can embed Vimeo and YouTube videos.

The videos are shown as expected when loaded within Trix. However, when showing them on a page using something like

<%= @section.content %>

Where content is my rich_text_field, the iframe get stripped away.

I added iframe to the allowed_tags using an initializer

#config/initializers/html_sanitizer.rb

Rails::Html::WhiteListSanitizer.allowed_tags << 'iframe'

And I also tried adding this to application.rb as Chris Oliver from GoRails did in his Rails conf talk

config.to_prepare do
  ActionText::ContentHelper.allowed_tags << 'iframe'
end

Do you have any idea as to why this is not working as expected?

1 Answers

I use this in an initializer for other tags, which works in Rails 6:

Rails::Html::WhiteListSanitizer.allowed_tags.add 'iframe'

Related