loofah 2.3.0 → 2.3.1

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: 521948af26b151c0584b5eabd8e60c8c31ff451d2b134da4bc632256feeb87f4
4
- data.tar.gz: 9b699d079c84a6c498fcb5be0e56f7c68ad7049bb0aa498e3413343803fcf585
3
+ metadata.gz: 1196afab25d29644d1961e4516ac317a2c38dee3295f35354c468e6a9318fa55
4
+ data.tar.gz: 2e07ff641edb37d2b0dce2933288da4667d4b680a586912af9c171db7dfb0a63
5
5
  SHA512:
6
- metadata.gz: 7781d0db35620637fd69051e3729db36f4d10712bab60038df78f523d72b991b8e8f86009655495b56ef69d5b97aa5a621cc22698bc4eaec06577bece6841ec6
7
- data.tar.gz: e42ab470cc2f3fbb5d0c3965b6a60fe698d0d076b3d87d58f6c4fa209531eac82188bef01c8005a94f3caa3f342ae7df4a850a4107fa043b618bdbd9f98c8d86
6
+ metadata.gz: 37ac2cdb0d136da417cff62e3845c5b71769f044d8150c636a549dc9ca4cf98bcef4c6d2b6e653eff56922b95d812ed39310a406c49366c14791456ca905e8fe
7
+ data.tar.gz: 0fa3cdd75a3d2950801a1cfe7f8d4cad6bb73bbec67d24ba25980c09a565f6c95c5d664c1789ccd62486d1917c685a5b0f762cc073a054bbb0f02fb0222688f0
@@ -1,6 +1,15 @@
1
1
  # Changelog
2
2
 
3
- ## 2.3.0 / unreleased
3
+ ## 2.3.1 / 2019-10-22
4
+
5
+ ### Security
6
+
7
+ Address CVE-2019-15587: Unsanitized JavaScript may occur in sanitized output when a crafted SVG element is republished.
8
+
9
+ This CVE's public notice is at https://github.com/flavorjones/loofah/issues/171
10
+
11
+
12
+ ## 2.3.0 / 2019-09-28
4
13
 
5
14
  ### Features
6
15
 
data/README.md CHANGED
@@ -14,17 +14,11 @@
14
14
 
15
15
  ## Description
16
16
 
17
- Loofah is a general library for manipulating and transforming HTML/XML
18
- documents and fragments. It's built on top of Nokogiri and libxml2, so
19
- it's fast and has a nice API.
17
+ Loofah is a general library for manipulating and transforming HTML/XML documents and fragments, built on top of Nokogiri.
20
18
 
21
- Loofah excels at HTML sanitization (XSS prevention). It includes some
22
- nice HTML sanitizers, which are based on HTML5lib's safelist, so it
23
- most likely won't make your codes less secure. (These statements have
24
- not been evaluated by Netexperts.)
19
+ Loofah excels at HTML sanitization (XSS prevention). It includes some nice HTML sanitizers, which are based on HTML5lib's safelist, so it most likely won't make your codes less secure. (These statements have not been evaluated by Netexperts.)
25
20
 
26
- ActiveRecord extensions for sanitization are available in the
27
- [`loofah-activerecord` gem](https://github.com/flavorjones/loofah-activerecord).
21
+ ActiveRecord extensions for sanitization are available in the [`loofah-activerecord` gem](https://github.com/flavorjones/loofah-activerecord).
28
22
 
29
23
 
30
24
  ## Features
@@ -28,7 +28,7 @@ require "loofah/html/document_fragment"
28
28
  #
29
29
  module Loofah
30
30
  # The version of Loofah you are using
31
- VERSION = "2.3.0"
31
+ VERSION = "2.3.1"
32
32
 
33
33
  class << self
34
34
  # Shortcut for Loofah::HTML::Document.parse
@@ -1,4 +1,4 @@
1
- require 'set'
1
+ require "set"
2
2
 
3
3
  module Loofah
4
4
  module HTML5 # :nodoc:
@@ -45,7 +45,6 @@ module Loofah
45
45
  #
46
46
  # </html5_license>
47
47
  module SafeList
48
-
49
48
  ACCEPTABLE_ELEMENTS = Set.new([
50
49
  "a",
51
50
  "abbr",
@@ -361,7 +360,6 @@ module Loofah
361
360
  "baseProfile",
362
361
  "bbox",
363
362
  "begin",
364
- "by",
365
363
  "calcMode",
366
364
  "cap-height",
367
365
  "class",
@@ -468,7 +466,6 @@ module Loofah
468
466
  "systemLanguage",
469
467
  "target",
470
468
  "text-anchor",
471
- "to",
472
469
  "transform",
473
470
  "type",
474
471
  "u1",
@@ -478,7 +475,6 @@ module Loofah
478
475
  "unicode",
479
476
  "unicode-range",
480
477
  "units-per-em",
481
- "values",
482
478
  "version",
483
479
  "viewBox",
484
480
  "visibility",
@@ -1,7 +1,6 @@
1
1
  require "helper"
2
2
 
3
3
  class IntegrationTestAdHoc < Loofah::TestCase
4
-
5
4
  context "blank input string" do
6
5
  context "fragment" do
7
6
  it "return a blank string" do
@@ -33,9 +32,9 @@ class IntegrationTestAdHoc < Loofah::TestCase
33
32
  html = "<p class=bar foo=bar abbr=bar />"
34
33
  sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
35
34
  node = sane.xpath("//p").first
36
- assert node.attributes['class']
37
- assert node.attributes['abbr']
38
- assert_nil node.attributes['foo']
35
+ assert node.attributes["class"]
36
+ assert node.attributes["abbr"]
37
+ assert_nil node.attributes["foo"]
39
38
  end
40
39
 
41
40
  def test_removal_of_illegal_url_in_href
@@ -45,14 +44,14 @@ class IntegrationTestAdHoc < Loofah::TestCase
45
44
  HTML
46
45
  sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
47
46
  nodes = sane.xpath("//a")
48
- assert_nil nodes.first.attributes['href']
49
- assert nodes.last.attributes['href']
47
+ assert_nil nodes.first.attributes["href"]
48
+ assert nodes.last.attributes["href"]
50
49
  end
51
50
 
52
51
  def test_css_sanitization
53
52
  html = "<p style='background-color: url(\"http://foo.com/\") ; background-color: #000 ;' />"
54
53
  sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
55
- assert_match %r/#000/, sane.inner_html
54
+ assert_match %r/#000/, sane.inner_html
56
55
  refute_match %r/foo\.com/, sane.inner_html
57
56
  end
58
57
 
@@ -75,7 +74,7 @@ class IntegrationTestAdHoc < Loofah::TestCase
75
74
  def test_whitewash_on_fragment
76
75
  html = "safe<frameset rows=\"*\"><frame src=\"http://example.com\"></frameset> <b>description</b>"
77
76
  whitewashed = Loofah.scrub_document(html, :whitewash).xpath("/html/body/*").to_s
78
- assert_equal "<p>safe</p><b>description</b>", whitewashed.gsub("\n","")
77
+ assert_equal "<p>safe</p><b>description</b>", whitewashed.gsub("\n", "")
79
78
  end
80
79
 
81
80
  def test_fragment_whitewash_on_microsofty_markup
@@ -86,11 +85,11 @@ class IntegrationTestAdHoc < Loofah::TestCase
86
85
  def test_document_whitewash_on_microsofty_markup
87
86
  whitewashed = Loofah.document(MSWORD_HTML).scrub!(:whitewash)
88
87
  assert_match %r(<p>Foo <b>BOLD</b></p>), whitewashed.to_s
89
- assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.xpath("/html/body/*").to_s
88
+ assert_equal "<p>Foo <b>BOLD</b></p>", whitewashed.xpath("/html/body/*").to_s
90
89
  end
91
90
 
92
91
  def test_return_empty_string_when_nothing_left
93
- assert_equal "", Loofah.scrub_document('<script>test</script>', :prune).text
92
+ assert_equal "", Loofah.scrub_document("<script>test</script>", :prune).text
94
93
  end
95
94
 
96
95
  def test_nested_script_cdata_tags_should_be_scrubbed
@@ -145,21 +144,20 @@ class IntegrationTestAdHoc < Loofah::TestCase
145
144
  #
146
145
  # https://git.gnome.org/browse/libxml2/tree/HTMLtree.c?h=v2.9.2#n714
147
146
  #
148
- {tag: "a", attr: "href"},
149
- {tag: "div", attr: "href"},
150
- {tag: "a", attr: "action"},
151
- {tag: "div", attr: "action"},
152
- {tag: "a", attr: "src"},
153
- {tag: "div", attr: "src"},
154
- {tag: "a", attr: "name"},
147
+ { tag: "a", attr: "href" },
148
+ { tag: "div", attr: "href" },
149
+ { tag: "a", attr: "action" },
150
+ { tag: "div", attr: "action" },
151
+ { tag: "a", attr: "src" },
152
+ { tag: "div", attr: "src" },
153
+ { tag: "a", attr: "name" },
155
154
  #
156
155
  # note that div+name is _not_ affected by the libxml2 issue.
157
156
  # but we test it anyway to ensure our logic isn't modifying
158
157
  # attributes that don't need modifying.
159
158
  #
160
- {tag: "div", attr: "name", unescaped: true},
159
+ { tag: "div", attr: "name", unescaped: true },
161
160
  ].each do |config|
162
-
163
161
  define_method "test_uri_escaping_of_#{config[:attr]}_attr_in_#{config[:tag]}_tag" do
164
162
  html = %{<#{config[:tag]} #{config[:attr]}='examp<!--" unsafeattr=foo()>-->le.com'>test</#{config[:tag]}>}
165
163
 
@@ -190,14 +188,32 @@ class IntegrationTestAdHoc < Loofah::TestCase
190
188
  end
191
189
  end
192
190
 
193
- # see:
194
- # - https://github.com/flavorjones/loofah/issues/154
195
- # - https://hackerone.com/reports/429267
196
- context "xss protection from svg xmlns:xlink animate attribute" do
197
- it "sanitizes appropriate attributes" do
198
- html = %Q{<svg><a xmlns:xlink=http://www.w3.org/1999/xlink xlink:href=?><circle r=400 /><animate attributeName=xlink:href begin=0 from=javascript:alert(1) to=%26>}
191
+ context "xss protection from svg animate attributes" do
192
+ # see recommendation from https://html5sec.org/#137
193
+ # to sanitize "to", "from", "values", and "by" attributes
194
+
195
+ it "sanitizes 'from', 'to', and 'by' attributes" do
196
+ # for CVE-2018-16468
197
+ # see:
198
+ # - https://github.com/flavorjones/loofah/issues/154
199
+ # - https://hackerone.com/reports/429267
200
+ html = %Q{<svg><a xmlns:xlink=http://www.w3.org/1999/xlink xlink:href=?><circle r=400 /><animate attributeName=xlink:href begin=0 from=javascript:alert(1) to=%26 by=5>}
201
+
199
202
  sanitized = Loofah.scrub_fragment(html, :escape)
200
203
  assert_nil sanitized.at_css("animate")["from"]
204
+ assert_nil sanitized.at_css("animate")["to"]
205
+ assert_nil sanitized.at_css("animate")["by"]
206
+ end
207
+
208
+ it "sanitizes 'values' attribute" do
209
+ # for CVE-2019-15587
210
+ # see:
211
+ # - https://github.com/flavorjones/loofah/issues/171
212
+ # - https://hackerone.com/reports/709009
213
+ html = %Q{<svg> <animate href="#foo" attributeName="href" values="javascript:alert('xss')"/> <a id="foo"> <circle r=400 /> </a> </svg>}
214
+
215
+ sanitized = Loofah.scrub_fragment(html, :escape)
216
+ assert_nil sanitized.at_css("animate")["values"]
201
217
  end
202
218
  end
203
219
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loofah
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Dalessio
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-28 00:00:00.000000000 Z
12
+ date: 2019-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -200,17 +200,11 @@ dependencies:
200
200
  - !ruby/object:Gem::Version
201
201
  version: '3.18'
202
202
  description: |-
203
- Loofah is a general library for manipulating and transforming HTML/XML
204
- documents and fragments. It's built on top of Nokogiri and libxml2, so
205
- it's fast and has a nice API.
203
+ Loofah is a general library for manipulating and transforming HTML/XML documents and fragments, built on top of Nokogiri.
206
204
 
207
- Loofah excels at HTML sanitization (XSS prevention). It includes some
208
- nice HTML sanitizers, which are based on HTML5lib's safelist, so it
209
- most likely won't make your codes less secure. (These statements have
210
- not been evaluated by Netexperts.)
205
+ Loofah excels at HTML sanitization (XSS prevention). It includes some nice HTML sanitizers, which are based on HTML5lib's safelist, so it most likely won't make your codes less secure. (These statements have not been evaluated by Netexperts.)
211
206
 
212
- ActiveRecord extensions for sanitization are available in the
213
- [`loofah-activerecord` gem](https://github.com/flavorjones/loofah-activerecord).
207
+ ActiveRecord extensions for sanitization are available in the [`loofah-activerecord` gem](https://github.com/flavorjones/loofah-activerecord).
214
208
  email:
215
209
  - mike.dalessio@gmail.com
216
210
  - bryan@brynary.com
@@ -289,5 +283,5 @@ rubygems_version: 3.0.3
289
283
  signing_key:
290
284
  specification_version: 4
291
285
  summary: Loofah is a general library for manipulating and transforming HTML/XML documents
292
- and fragments
286
+ and fragments, built on top of Nokogiri
293
287
  test_files: []