Skip to content

Commit 46daa07

Browse files
committed
Merge branch 'jf.safelist'
2 parents 6c5ff2d + 775ab31 commit 46daa07

13 files changed

Lines changed: 82 additions & 56 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
* CSS hex values are no longer limited to lowercase hex. Previously uppercase hex were scrubbed. [#165] (Thanks, @asok!)
1818

1919

20+
### Deprecations / Name Changes
21+
22+
The following method and constants are hereby deprecated, and will be completely removed in a future release:
23+
24+
* Deprecate `Loofah::Helpers::ActionView.white_list_sanitizer`, please use `Loofah::Helpers::ActionView.safe_list_sanitizer` instead.
25+
* Deprecate `Loofah::Helpers::ActionView::WhiteListSanitizer`, please use `Loofah::Helpers::ActionView::SafeListSanitizer` instead.
26+
* Deprecate `Loofah::HTML5::WhiteList`, please use `Loofah::HTML5::SafeList` instead.
27+
28+
Thanks to @JuanitoFatas for submitting these changes in #164 and for making the language used in Loofah more inclusive.
29+
30+
2031
## 2.2.3 / 2018-10-30
2132

2233
### Security

Manifest.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ lib/loofah/html/document.rb
1717
lib/loofah/html/document_fragment.rb
1818
lib/loofah/html5/libxml2_workarounds.rb
1919
lib/loofah/html5/scrub.rb
20-
lib/loofah/html5/whitelist.rb
20+
lib/loofah/html5/safelist.rb
2121
lib/loofah/instance_methods.rb
2222
lib/loofah/metahelpers.rb
2323
lib/loofah/scrubber.rb

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ documents and fragments. It's built on top of Nokogiri and libxml2, so
1919
it's fast and has a nice API.
2020

2121
Loofah excels at HTML sanitization (XSS prevention). It includes some
22-
nice HTML sanitizers, which are based on HTML5lib's whitelist, so it
22+
nice HTML sanitizers, which are based on HTML5lib's safelist, so it
2323
most likely won't make your codes less secure. (These statements have
2424
not been evaluated by Netexperts.)
2525

@@ -29,7 +29,7 @@ ActiveRecord extensions for sanitization are available in the
2929

3030
## Features
3131

32-
* Easily write custom scrubbers for HTML/XML leveraging the sweetness of Nokogiri (and HTML5lib's whitelists).
32+
* Easily write custom scrubbers for HTML/XML leveraging the sweetness of Nokogiri (and HTML5lib's safelists).
3333
* Common HTML sanitizing tasks are built-in:
3434
* _Strip_ unsafe tags, leaving behind only the inner text.
3535
* _Prune_ unsafe tags and their subtrees, removing all traces that they ever existed.
@@ -221,7 +221,7 @@ Loofah.xml_document(File.read('plague.xml')).scrub!(bring_out_your_dead)
221221
=== Built-In HTML Scrubbers
222222

223223
Loofah comes with a set of sanitizing scrubbers that use HTML5lib's
224-
whitelist algorithm:
224+
safelist algorithm:
225225

226226
``` ruby
227227
doc.scrub!(:strip) # replaces unknown/unsafe tags with their inner text

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ task :doc_upload_to_rubyforge => :docs do
7070
end
7171
end
7272

73-
desc "generate whitelists from W3C specifications"
74-
task :generate_whitelists do
75-
load "tasks/generate-whitelists"
73+
desc "generate safelists from W3C specifications"
74+
task :generate_safelists do
75+
load "tasks/generate-safelists"
7676
end
7777

7878
Concourse.new("loofah", fly_target: "ci") do |c|

lib/loofah.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'loofah/metahelpers'
66
require 'loofah/elements'
77

8-
require 'loofah/html5/whitelist'
8+
require 'loofah/html5/safelist'
99
require 'loofah/html5/libxml2_workarounds'
1010
require 'loofah/html5/scrub'
1111

lib/loofah/helpers.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ def full_sanitizer
4646
@full_sanitizer ||= ::Loofah::Helpers::ActionView::FullSanitizer.new
4747
end
4848

49+
def safe_list_sanitizer
50+
@safe_list_sanitizer ||= ::Loofah::Helpers::ActionView::SafeListSanitizer.new
51+
end
52+
4953
def white_list_sanitizer
50-
@white_list_sanitizer ||= ::Loofah::Helpers::ActionView::WhiteListSanitizer.new
54+
warn "warning: white_list_sanitizer is deprecated, please use safe_list_sanitizer instead."
55+
safe_list_sanitizer
5156
end
5257
end
5358

@@ -73,13 +78,13 @@ def sanitize html, *args
7378
#
7479
# To use by default, call this in an application initializer:
7580
#
76-
# ActionView::Helpers::SanitizeHelper.white_list_sanitizer = ::Loofah::Helpers::ActionView::WhiteListSanitizer.new
81+
# ActionView::Helpers::SanitizeHelper.safe_list_sanitizer = ::Loofah::Helpers::ActionView::SafeListSanitizer.new
7782
#
7883
# Or, to generally opt-in to Loofah's view sanitizers:
7984
#
8085
# Loofah::Helpers::ActionView.set_as_default_sanitizer
8186
#
82-
class WhiteListSanitizer
87+
class SafeListSanitizer
8388
def sanitize html, *args
8489
Loofah::Helpers.sanitize html
8590
end
@@ -88,6 +93,11 @@ def sanitize_css style_string, *args
8893
Loofah::Helpers.sanitize_css style_string
8994
end
9095
end
96+
97+
WhiteListSanitizer = SafeListSanitizer
98+
if Object.respond_to?(:deprecate_constant)
99+
deprecate_constant :WhiteListSanitizer
100+
end
91101
end
92102
end
93103
end
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Loofah
44
module HTML5 # :nodoc:
55
#
6-
# HTML whitelist lifted from HTML5lib sanitizer code:
6+
# HTML safelist lifted from HTML5lib sanitizer code:
77
#
88
# http://code.google.com/p/html5lib/
99
#
@@ -44,7 +44,7 @@ module HTML5 # :nodoc:
4444
# DEALINGS IN THE SOFTWARE.
4545
#
4646
# </html5_license>
47-
module WhiteList
47+
module SafeList
4848

4949
ACCEPTABLE_ELEMENTS = Set.new([
5050
"a",
@@ -790,6 +790,11 @@ module WhiteList
790790
ALLOWED_ELEMENTS_WITH_LIBXML2 = ALLOWED_ELEMENTS + TAGS_SAFE_WITH_LIBXML2
791791
end
792792

793-
::Loofah::MetaHelpers.add_downcased_set_members_to_all_set_constants ::Loofah::HTML5::WhiteList
793+
WhiteList = SafeList
794+
if Object.respond_to?(:deprecate_constant)
795+
deprecate_constant :WhiteList
796+
end
797+
798+
::Loofah::MetaHelpers.add_downcased_set_members_to_all_set_constants ::Loofah::HTML5::SafeList
794799
end
795800
end

lib/loofah/html5/scrub.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Scrub
1212
class << self
1313

1414
def allowed_element? element_name
15-
::Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS_WITH_LIBXML2.include? element_name
15+
::Loofah::HTML5::SafeList::ALLOWED_ELEMENTS_WITH_LIBXML2.include? element_name
1616
end
1717

1818
# alternative implementation of the html5lib attribute scrubbing algorithm
@@ -28,31 +28,31 @@ def scrub_attributes node
2828
next
2929
end
3030

31-
unless WhiteList::ALLOWED_ATTRIBUTES.include?(attr_name)
31+
unless SafeList::ALLOWED_ATTRIBUTES.include?(attr_name)
3232
attr_node.remove
3333
next
3434
end
3535

36-
if WhiteList::ATTR_VAL_IS_URI.include?(attr_name)
36+
if SafeList::ATTR_VAL_IS_URI.include?(attr_name)
3737
# this block lifted nearly verbatim from HTML5 sanitization
3838
val_unescaped = CGI.unescapeHTML(attr_node.value).gsub(CONTROL_CHARACTERS,'').downcase
39-
if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ && ! WhiteList::ALLOWED_PROTOCOLS.include?(val_unescaped.split(WhiteList::PROTOCOL_SEPARATOR)[0])
39+
if val_unescaped =~ /^[a-z0-9][-+.a-z0-9]*:/ && ! SafeList::ALLOWED_PROTOCOLS.include?(val_unescaped.split(SafeList::PROTOCOL_SEPARATOR)[0])
4040
attr_node.remove
4141
next
42-
elsif val_unescaped.split(WhiteList::PROTOCOL_SEPARATOR)[0] == 'data'
42+
elsif val_unescaped.split(SafeList::PROTOCOL_SEPARATOR)[0] == 'data'
4343
# permit only allowed data mediatypes
44-
mediatype = val_unescaped.split(WhiteList::PROTOCOL_SEPARATOR)[1]
44+
mediatype = val_unescaped.split(SafeList::PROTOCOL_SEPARATOR)[1]
4545
mediatype, _ = mediatype.split(';')[0..1] if mediatype
46-
if mediatype && !WhiteList::ALLOWED_URI_DATA_MEDIATYPES.include?(mediatype)
46+
if mediatype && !SafeList::ALLOWED_URI_DATA_MEDIATYPES.include?(mediatype)
4747
attr_node.remove
4848
next
4949
end
5050
end
5151
end
52-
if WhiteList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name)
52+
if SafeList::SVG_ATTR_VAL_ALLOWS_REF.include?(attr_name)
5353
attr_node.value = attr_node.value.gsub(/url\s*\(\s*[^#\s][^)]+?\)/m, ' ') if attr_node.value
5454
end
55-
if WhiteList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m
55+
if SafeList::SVG_ALLOW_LOCAL_HREF.include?(node.name) && attr_name == 'xlink:href' && attr_node.value =~ /^\s*[^#\s].*/m
5656
attr_node.remove
5757
next
5858
end
@@ -79,14 +79,14 @@ def scrub_css style
7979
style_tree.each do |node|
8080
next unless node[:node] == :property
8181
next if node[:children].any? do |child|
82-
[:url, :bad_url].include?(child[:node]) || (child[:node] == :function && !WhiteList::ALLOWED_CSS_FUNCTIONS.include?(child[:name].downcase))
82+
[:url, :bad_url].include?(child[:node]) || (child[:node] == :function && !SafeList::ALLOWED_CSS_FUNCTIONS.include?(child[:name].downcase))
8383
end
8484
name = node[:name].downcase
85-
if WhiteList::ALLOWED_CSS_PROPERTIES.include?(name) || WhiteList::ALLOWED_SVG_PROPERTIES.include?(name)
85+
if SafeList::ALLOWED_CSS_PROPERTIES.include?(name) || SafeList::ALLOWED_SVG_PROPERTIES.include?(name)
8686
sanitized_tree << node << CRASS_SEMICOLON
87-
elsif WhiteList::SHORTHAND_CSS_PROPERTIES.include?(name.split('-').first)
87+
elsif SafeList::SHORTHAND_CSS_PROPERTIES.include?(name.split('-').first)
8888
value = node[:value].split.map do |keyword|
89-
if WhiteList::ALLOWED_CSS_KEYWORDS.include?(keyword) || keyword =~ CSS_KEYWORDISH
89+
if SafeList::ALLOWED_CSS_KEYWORDS.include?(keyword) || keyword =~ CSS_KEYWORDISH
9090
keyword
9191
end
9292
end.compact

lib/loofah/scrubbers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Loofah
22
#
33
# Loofah provides some built-in scrubbers for sanitizing with
4-
# HTML5lib's whitelist and for accomplishing some common
4+
# HTML5lib's safelist and for accomplishing some common
55
# transformation tasks.
66
#
77
#

loofah.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Gem::Specification.new do |s|
99
s.require_paths = ["lib".freeze]
1010
s.authors = ["Mike Dalessio".freeze, "Bryan Helmkamp".freeze]
1111
s.date = "2018-02-12"
12-
s.description = "Loofah is a general library for manipulating and transforming HTML/XML\ndocuments and fragments. It's built on top of Nokogiri and libxml2, so\nit's fast and has a nice API.\n\nLoofah excels at HTML sanitization (XSS prevention). It includes some\nnice HTML sanitizers, which are based on HTML5lib's whitelist, so it\nmost likely won't make your codes less secure. (These statements have\nnot been evaluated by Netexperts.)\n\nActiveRecord extensions for sanitization are available in the\n[`loofah-activerecord` gem](https://github.com/flavorjones/loofah-activerecord).".freeze
12+
s.description = "Loofah is a general library for manipulating and transforming HTML/XML\ndocuments and fragments. It's built on top of Nokogiri and libxml2, so\nit's fast and has a nice API.\n\nLoofah excels at HTML sanitization (XSS prevention). It includes some\nnice HTML sanitizers, which are based on HTML5lib's safelist, so it\nmost likely won't make your codes less secure. (These statements have\nnot been evaluated by Netexperts.)\n\nActiveRecord extensions for sanitization are available in the\n[`loofah-activerecord` gem](https://github.com/flavorjones/loofah-activerecord).".freeze
1313
s.email = ["mike.dalessio@gmail.com".freeze, "bryan@brynary.com".freeze]
1414
s.extra_rdoc_files = ["CHANGELOG.md".freeze, "MIT-LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze, "CHANGELOG.md".freeze, "README.md".freeze]
15-
s.files = [".gemtest".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "MIT-LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze, "Rakefile".freeze, "benchmark/benchmark.rb".freeze, "benchmark/fragment.html".freeze, "benchmark/helper.rb".freeze, "benchmark/www.slashdot.com.html".freeze, "lib/loofah.rb".freeze, "lib/loofah/elements.rb".freeze, "lib/loofah/helpers.rb".freeze, "lib/loofah/html/document.rb".freeze, "lib/loofah/html/document_fragment.rb".freeze, "lib/loofah/html5/scrub.rb".freeze, "lib/loofah/html5/whitelist.rb".freeze, "lib/loofah/instance_methods.rb".freeze, "lib/loofah/metahelpers.rb".freeze, "lib/loofah/scrubber.rb".freeze, "lib/loofah/scrubbers.rb".freeze, "lib/loofah/xml/document.rb".freeze, "lib/loofah/xml/document_fragment.rb".freeze, "test/assets/testdata_sanitizer_tests1.dat".freeze, "test/helper.rb".freeze, "test/html5/test_sanitizer.rb".freeze, "test/integration/test_ad_hoc.rb".freeze, "test/integration/test_helpers.rb".freeze, "test/integration/test_html.rb".freeze, "test/integration/test_scrubbers.rb".freeze, "test/integration/test_xml.rb".freeze, "test/unit/test_api.rb".freeze, "test/unit/test_encoding.rb".freeze, "test/unit/test_helpers.rb".freeze, "test/unit/test_scrubber.rb".freeze, "test/unit/test_scrubbers.rb".freeze]
15+
s.files = [".gemtest".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "MIT-LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze, "Rakefile".freeze, "benchmark/benchmark.rb".freeze, "benchmark/fragment.html".freeze, "benchmark/helper.rb".freeze, "benchmark/www.slashdot.com.html".freeze, "lib/loofah.rb".freeze, "lib/loofah/elements.rb".freeze, "lib/loofah/helpers.rb".freeze, "lib/loofah/html/document.rb".freeze, "lib/loofah/html/document_fragment.rb".freeze, "lib/loofah/html5/scrub.rb".freeze, "lib/loofah/html5/safelist.rb".freeze, "lib/loofah/instance_methods.rb".freeze, "lib/loofah/metahelpers.rb".freeze, "lib/loofah/scrubber.rb".freeze, "lib/loofah/scrubbers.rb".freeze, "lib/loofah/xml/document.rb".freeze, "lib/loofah/xml/document_fragment.rb".freeze, "test/assets/testdata_sanitizer_tests1.dat".freeze, "test/helper.rb".freeze, "test/html5/test_sanitizer.rb".freeze, "test/integration/test_ad_hoc.rb".freeze, "test/integration/test_helpers.rb".freeze, "test/integration/test_html.rb".freeze, "test/integration/test_scrubbers.rb".freeze, "test/integration/test_xml.rb".freeze, "test/unit/test_api.rb".freeze, "test/unit/test_encoding.rb".freeze, "test/unit/test_helpers.rb".freeze, "test/unit/test_scrubber.rb".freeze, "test/unit/test_scrubbers.rb".freeze]
1616
s.homepage = "https://github.com/flavorjones/loofah".freeze
1717
s.licenses = ["MIT".freeze]
1818
s.rdoc_options = ["--main".freeze, "README.md".freeze]

0 commit comments

Comments
 (0)