123456789_123456789_123456789_123456789_123456789_

Module: ActionView::Helpers::SanitizeHelper

Overview

Action View Sanitize Helpers

The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements. These helper methods extend Action View making them callable within your template files.

Class Attribute Summary

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Attribute Summary

Instance Method Summary

Class Attribute Details

.sanitizer_vendor (rw) Also known as: #sanitizer_vendor

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/sanitize_helper.rb', line 14

mattr_accessor :sanitizer_vendor, default: Rails::HTML4::Sanitizer

Instance Attribute Details

#sanitizer_vendor (rw)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/sanitize_helper.rb', line 14

mattr_accessor :sanitizer_vendor, default: Rails::HTML4::Sanitizer

Instance Method Details

#sanitize(html, options = {})

Sanitizes HTML input, stripping all but known-safe tags and attributes.

It also strips href / src attributes with unsafe protocols like javascript:, while also protecting against attempts to use Unicode, ASCII, and hex character references to work around these protocol filters.

The default sanitizer is Rails::HTML5::SafeListSanitizer. See Rails HTML Sanitizers for more information.

Custom sanitization rules can also be provided.

Warning: Adding disallowed tags or attributes to the allowlists may introduce vulnerabilities into your application. Please rely on the default allowlists whenever possible, because they are curated to maintain security and safety. If you think that the default allowlists should be expanded, please open an issue on the rails-html-sanitizer project.

Please note that sanitizing user-provided text does not guarantee that the resulting markup is valid or even well-formed.

The return value is HTML markup. It is safe only as element content where the HTML parser applies the "in body" insertion mode rules, such as inside a

,

or element. Anywhere else it is unsafe or incorrect, including in an attribute value and inside a