loofah 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of loofah might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29f0764dd4fc0eed44139b573bd3708917cab618126b094b9faa42d26a29d949
4
- data.tar.gz: e1e9cc2ecbd68de48d1f2554a65b86bed0756616008cf9c9a7ed62af1197afa4
3
+ metadata.gz: 052a847ba3f873261fa917f028171997ba40b96a5afc4339d98dbfd252905a91
4
+ data.tar.gz: 1e348bd51955411df0ed0b170460b30fa150594b8c7a60a40c80de0d485f9e94
5
5
  SHA512:
6
- metadata.gz: 05bc54adcab4ee55e52f69685366ba81e492a6b6c25c8e282d79d4ec85349f8ac37c3e34b74ed81089bda662ebed620c208a7a46bc64f4a504ec1bf51f7c8bf9
7
- data.tar.gz: 8b0e5d75ab88d683240183b5b3e4ed3d1a1fd26bac0d89780ce64722a3d05cba95c42376208e294ad1b3b215fcb90a795e479a2d0e8a3fd643d3b136e88bb562
6
+ metadata.gz: 013d4c78bbaedf2b845d33b4bca6c6e483a36b8b774931dea2071e080657e34e2725ee4dffa48db6eb389898640b8b475009ac70efc5e0b319646ae5b7822a85
7
+ data.tar.gz: 26742f775c503fbe56255e46963887ae769182574bc6cd7070168c50e92a5ddefa83208ff8930346f6ce7bad74624913221b84f5f3abbc60254c1530595c858e
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.5.0 / 2020-04-05
4
+
5
+ ### Features
6
+
7
+ * Allow more CSS length units: "ch", "vw", "vh", "Q", "lh", "vmin", "vmax". [#178] (Thanks, @JuanitoFatas!)
8
+
9
+
10
+ ### Fixes
11
+
12
+ * Remove comments from `Loofah::HTML::Document`s that exist outside the `html` element. [#80]
13
+
14
+
15
+ ### Other changes
16
+
17
+ * Gem metadata being set [#181] (Thanks, @JuanitoFatas!)
18
+ * Test files removed from gem file [#180,#166,#159] (Thanks, @JuanitoFatas and @greysteil!)
19
+
20
+
3
21
  ## 2.4.0 / 2019-11-25
4
22
 
5
23
  ### Features
@@ -1,4 +1,3 @@
1
- .gemtest
2
1
  CHANGELOG.md
3
2
  Gemfile
4
3
  MIT-LICENSE.txt
@@ -24,18 +23,3 @@ lib/loofah/scrubber.rb
24
23
  lib/loofah/scrubbers.rb
25
24
  lib/loofah/xml/document.rb
26
25
  lib/loofah/xml/document_fragment.rb
27
- test/assets/msword.html
28
- test/assets/testdata_sanitizer_tests1.dat
29
- test/helper.rb
30
- test/html5/test_sanitizer.rb
31
- test/html5/test_scrub.rb
32
- test/integration/test_ad_hoc.rb
33
- test/integration/test_helpers.rb
34
- test/integration/test_html.rb
35
- test/integration/test_scrubbers.rb
36
- test/integration/test_xml.rb
37
- test/unit/test_api.rb
38
- test/unit/test_encoding.rb
39
- test/unit/test_helpers.rb
40
- test/unit/test_scrubber.rb
41
- test/unit/test_scrubbers.rb
data/Rakefile CHANGED
@@ -11,10 +11,16 @@ Hoe.spec "loofah" do
11
11
  developer "Mike Dalessio", "mike.dalessio@gmail.com"
12
12
  developer "Bryan Helmkamp", "bryan@brynary.com"
13
13
 
14
- self.extra_rdoc_files = FileList["*.md"]
15
14
  self.history_file = "CHANGELOG.md"
16
15
  self.readme_file = "README.md"
17
16
  self.license "MIT"
17
+ self.urls = {
18
+ "home" => "https://github.com/flavorjones/loofah",
19
+ "bugs" => "https://github.com/flavorjones/loofah/issues",
20
+ "doco" => "https://www.rubydoc.info/gems/loofah/",
21
+ "clog" => "https://github.com/flavorjones/loofah/master/CHANGELOG.md",
22
+ "code" => "https://github.com/flavorjones/loofah",
23
+ }
18
24
 
19
25
  extra_deps << ["nokogiri", ">=1.5.9"]
20
26
  extra_deps << ["crass", "~> 1.0.2"]
@@ -23,7 +23,7 @@ def compare_scrub_methods
23
23
  end
24
24
 
25
25
  module TestSet
26
- def test_set options={}
26
+ def test_set(options = {})
27
27
  scale = options[:rehearse] ? 10 : 1
28
28
  puts self.class.name
29
29
 
@@ -49,6 +49,7 @@ end
49
49
 
50
50
  class HeadToHeadRailsSanitize < Measure
51
51
  include TestSet
52
+
52
53
  def bench(content, ntimes, fragment_p)
53
54
  clear_measure
54
55
 
@@ -65,6 +66,7 @@ end
65
66
 
66
67
  class HeadToHeadRailsStripTags < Measure
67
68
  include TestSet
69
+
68
70
  def bench(content, ntimes, fragment_p)
69
71
  clear_measure
70
72
 
@@ -81,6 +83,7 @@ end
81
83
 
82
84
  class HeadToHeadSanitizerSanitize < Measure
83
85
  include TestSet
86
+
84
87
  def bench(content, ntimes, fragment_p)
85
88
  clear_measure
86
89
 
@@ -100,6 +103,7 @@ end
100
103
 
101
104
  class HeadToHeadHtml5LibSanitize < Measure
102
105
  include TestSet
106
+
103
107
  def bench(content, ntimes, fragment_p)
104
108
  clear_measure
105
109
 
@@ -120,6 +124,7 @@ end
120
124
 
121
125
  class HeadToHeadHTMLFilter < Measure
122
126
  include TestSet
127
+
123
128
  def bench(content, ntimes, fragment_p)
124
129
  clear_measure
125
130
 
@@ -1,13 +1,13 @@
1
- require 'rubygems'
2
- require 'open-uri'
3
- require 'hpricot'
1
+ require "rubygems"
2
+ require "open-uri"
3
+ require "hpricot"
4
4
  require File.expand_path(File.dirname(__FILE__) + "/../lib/loofah")
5
- require 'benchmark'
5
+ require "benchmark"
6
6
  require "action_view"
7
7
  require "action_controller/vendor/html-scanner"
8
8
  require "sanitize"
9
- require 'hitimes'
10
- require 'htmlfilter'
9
+ require "hitimes"
10
+ require "htmlfilter"
11
11
 
12
12
  unless defined?(HTMLFilter)
13
13
  HTMLFilter = HtmlFilter
@@ -19,20 +19,20 @@ class RailsSanitize
19
19
  end
20
20
 
21
21
  class HTML5libSanitize
22
- require 'html5/html5parser'
23
- require 'html5/liberalxmlparser'
24
- require 'html5/treewalkers'
25
- require 'html5/treebuilders'
26
- require 'html5/serializer'
27
- require 'html5/sanitizer'
22
+ require "html5/html5parser"
23
+ require "html5/liberalxmlparser"
24
+ require "html5/treewalkers"
25
+ require "html5/treebuilders"
26
+ require "html5/serializer"
27
+ require "html5/sanitizer"
28
28
 
29
29
  include HTML5
30
30
 
31
31
  def sanitize(html)
32
32
  HTMLParser.parse_fragment(html, {
33
- :tokenizer => HTMLSanitizer,
34
- :encoding => 'utf-8',
35
- :tree => TreeBuilders::REXML::TreeBuilder
33
+ :tokenizer => HTMLSanitizer,
34
+ :encoding => "utf-8",
35
+ :tree => TreeBuilders::REXML::TreeBuilder,
36
36
  }).to_s
37
37
  end
38
38
  end
@@ -29,13 +29,13 @@ require "loofah/html/document_fragment"
29
29
  #
30
30
  module Loofah
31
31
  # The version of Loofah you are using
32
- VERSION = "2.4.0"
32
+ VERSION = "2.5.0"
33
33
 
34
34
  class << self
35
35
  # Shortcut for Loofah::HTML::Document.parse
36
36
  # This method accepts the same parameters as Nokogiri::HTML::Document.parse
37
37
  def document(*args, &block)
38
- Loofah::HTML::Document.parse(*args, &block)
38
+ remove_comments_before_html_element Loofah::HTML::Document.parse(*args, &block)
39
39
  end
40
40
 
41
41
  # Shortcut for Loofah::HTML::DocumentFragment.parse
@@ -80,5 +80,23 @@ module Loofah
80
80
  def remove_extraneous_whitespace(string)
81
81
  string.gsub(/\n\s*\n\s*\n/, "\n\n")
82
82
  end
83
+
84
+ private
85
+
86
+ # remove comments that exist outside of the HTML element.
87
+ #
88
+ # these comments are allowed by the HTML spec:
89
+ #
90
+ # https://www.w3.org/TR/html401/struct/global.html#h-7.1
91
+ #
92
+ # but are not scrubbed by Loofah because these nodes don't meet
93
+ # the contract that scrubbers expect of a node (e.g., it can be
94
+ # replaced, sibling and children nodes can be created).
95
+ def remove_comments_before_html_element(doc)
96
+ doc.children.each do |child|
97
+ child.unlink if child.comment?
98
+ end
99
+ doc
100
+ end
83
101
  end
84
102
  end
@@ -1,90 +1,90 @@
1
1
  # frozen_string_literal: true
2
- require 'set'
2
+ require "set"
3
3
 
4
4
  module Loofah
5
5
  module Elements
6
6
  STRICT_BLOCK_LEVEL_HTML4 = Set.new %w[
7
- address
8
- blockquote
9
- center
10
- dir
11
- div
12
- dl
13
- fieldset
14
- form
15
- h1
16
- h2
17
- h3
18
- h4
19
- h5
20
- h6
21
- hr
22
- isindex
23
- menu
24
- noframes
25
- noscript
26
- ol
27
- p
28
- pre
29
- table
30
- ul
31
- ]
7
+ address
8
+ blockquote
9
+ center
10
+ dir
11
+ div
12
+ dl
13
+ fieldset
14
+ form
15
+ h1
16
+ h2
17
+ h3
18
+ h4
19
+ h5
20
+ h6
21
+ hr
22
+ isindex
23
+ menu
24
+ noframes
25
+ noscript
26
+ ol
27
+ p
28
+ pre
29
+ table
30
+ ul
31
+ ]
32
32
 
33
33
  # https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
34
34
  STRICT_BLOCK_LEVEL_HTML5 = Set.new %w[
35
- address
36
- article
37
- aside
38
- blockquote
39
- canvas
40
- dd
41
- div
42
- dl
43
- dt
44
- fieldset
45
- figcaption
46
- figure
47
- footer
48
- form
49
- h1
50
- h2
51
- h3
52
- h4
53
- h5
54
- h6
55
- header
56
- hgroup
57
- hr
58
- li
59
- main
60
- nav
61
- noscript
62
- ol
63
- output
64
- p
65
- pre
66
- section
67
- table
68
- tfoot
69
- ul
70
- video
71
- ]
35
+ address
36
+ article
37
+ aside
38
+ blockquote
39
+ canvas
40
+ dd
41
+ div
42
+ dl
43
+ dt
44
+ fieldset
45
+ figcaption
46
+ figure
47
+ footer
48
+ form
49
+ h1
50
+ h2
51
+ h3
52
+ h4
53
+ h5
54
+ h6
55
+ header
56
+ hgroup
57
+ hr
58
+ li
59
+ main
60
+ nav
61
+ noscript
62
+ ol
63
+ output
64
+ p
65
+ pre
66
+ section
67
+ table
68
+ tfoot
69
+ ul
70
+ video
71
+ ]
72
72
 
73
73
  STRICT_BLOCK_LEVEL = STRICT_BLOCK_LEVEL_HTML4 + STRICT_BLOCK_LEVEL_HTML5
74
74
 
75
75
  # The following elements may also be considered block-level
76
76
  # elements since they may contain block-level elements
77
77
  LOOSE_BLOCK_LEVEL = Set.new %w[dd
78
- dt
79
- frameset
80
- li
81
- tbody
82
- td
83
- tfoot
84
- th
85
- thead
86
- tr
87
- ]
78
+ dt
79
+ frameset
80
+ li
81
+ tbody
82
+ td
83
+ tfoot
84
+ th
85
+ thead
86
+ tr
87
+ ]
88
88
 
89
89
  BLOCK_LEVEL = STRICT_BLOCK_LEVEL + LOOSE_BLOCK_LEVEL
90
90
  end
@@ -28,7 +28,7 @@ module Loofah
28
28
  #
29
29
  # Loofah::Helpers.sanitize_css("display:block;background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg)") # => "display: block;"
30
30
  #
31
- def sanitize_css style_string
31
+ def sanitize_css(style_string)
32
32
  ::Loofah::HTML5::Scrub.scrub_css style_string
33
33
  end
34
34
 
@@ -69,7 +69,7 @@ module Loofah
69
69
  # Loofah::Helpers::ActionView.set_as_default_sanitizer
70
70
  #
71
71
  class FullSanitizer
72
- def sanitize html, *args
72
+ def sanitize(html, *args)
73
73
  Loofah::Helpers.strip_tags html
74
74
  end
75
75
  end
@@ -86,11 +86,11 @@ module Loofah
86
86
  # Loofah::Helpers::ActionView.set_as_default_sanitizer
87
87
  #
88
88
  class SafeListSanitizer
89
- def sanitize html, *args
89
+ def sanitize(html, *args)
90
90
  Loofah::Helpers.sanitize html
91
91
  end
92
92
 
93
- def sanitize_css style_string, *args
93
+ def sanitize_css(style_string, *args)
94
94
  Loofah::Helpers.sanitize_css style_string
95
95
  end
96
96
  end
@@ -15,10 +15,10 @@ module Loofah
15
15
  # constructor. Applications should use Loofah.fragment to
16
16
  # parse a fragment.
17
17
  #
18
- def parse tags, encoding = nil
18
+ def parse(tags, encoding = nil)
19
19
  doc = Loofah::HTML::Document.new
20
20
 
21
- encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : 'UTF-8'
21
+ encoding ||= tags.respond_to?(:encoding) ? tags.encoding.name : "UTF-8"
22
22
  doc.encoding = encoding
23
23
 
24
24
  new(doc, tags)
@@ -31,6 +31,7 @@ module Loofah
31
31
  def to_s
32
32
  serialize_root.children.to_s
33
33
  end
34
+
34
35
  alias :serialize :to_s
35
36
 
36
37
  def serialize_root
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
- require 'set'
3
+ require "set"
4
4
 
5
5
  module Loofah
6
6
  #
@@ -17,11 +17,11 @@ module Loofah
17
17
  # see comments about CVE-2018-8048 within the tests for more information
18
18
  #
19
19
  BROKEN_ESCAPING_ATTRIBUTES = Set.new %w[
20
- href
21
- action
22
- src
23
- name
24
- ]
25
- BROKEN_ESCAPING_ATTRIBUTES_QUALIFYING_TAG = {"name" => "a"}
20
+ href
21
+ action
22
+ src
23
+ name
24
+ ]
25
+ BROKEN_ESCAPING_ATTRIBUTES_QUALIFYING_TAG = { "name" => "a" }
26
26
  end
27
27
  end