rails-html-sanitizer 1.0.3 → 1.0.4

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

Potentially problematic release.


This version of rails-html-sanitizer might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 44e7ba72869ce5a5b6aa4f202dced7073ef94b72
4
- data.tar.gz: b5410baf4f05cc97449852a7b3b4e36774a9942d
2
+ SHA256:
3
+ metadata.gz: f1aa629ae03d828f900932e2272c2d13baf2eae94adb214896cdf2eb959e4172
4
+ data.tar.gz: 970c65b32aa93c659e6483e8b798ea23fa8b8eadb1963fba813dd33ba6432ae2
5
5
  SHA512:
6
- metadata.gz: 9ea541f36dbc6de129d6bd889a8b198bf5e4805a578e204dc21dfc01c29551f869e064b7c315a9cd7e2732cef58ad820851684df55568922135dd4866f5d8ff7
7
- data.tar.gz: ff206594a72e31e5504f935b437ea105327f7540d5d1a8530f202d35419c278f9d78a5e7f413e86c519bf7bf12b54341aadb7591cfa719f35ea1693d4d4998b2
6
+ metadata.gz: c97587f6427b9e67e76050f21ab8f39148fd0ff47e87282a4a13802a6ae02ffa62034a187a8e5cfd0577e53d0f0cbc8e2e72abce3171d7f6139f186f1b75e1a2
7
+ data.tar.gz: 411f2f9593fda42880b3ed9fcb99431e353c133d36a74e0aed52fa3959efa4bd8cc6aad5d90dddfc4565b0fabc80d68e9cfbf8cea055ae9463cba326f0735dc2
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2013-2015 Rafael Mendonça França, Kasper Timm Hansen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.md CHANGED
@@ -99,17 +99,15 @@ You can also create custom scrubbers in your application if you want to.
99
99
 
100
100
  ```ruby
101
101
  class CommentScrubber < Rails::Html::PermitScrubber
102
- def allowed_node?(node)
103
- !%w(form script comment blockquote).include?(node.name)
102
+ def initialize
103
+ super
104
+ self.tags = %w( form script comment blockquote )
105
+ self.attributes = %w( style )
104
106
  end
105
107
 
106
108
  def skip_node?(node)
107
109
  node.text?
108
110
  end
109
-
110
- def scrub_attribute?(name)
111
- name == "style"
112
- end
113
111
  end
114
112
  ```
115
113
 
@@ -61,7 +61,7 @@ module Rails
61
61
  # Sanitizes html and css from an extensive white list (see link further down).
62
62
  #
63
63
  # === Whitespace
64
- # We can't make any guarentees about whitespace being kept or stripped.
64
+ # We can't make any guarantees about whitespace being kept or stripped.
65
65
  # Loofah uses Nokogiri, which wraps either a C or Java parser for the
66
66
  # respective Ruby implementation.
67
67
  # Those two parsers determine how whitespace is ultimately handled.
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module Html
3
3
  class Sanitizer
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.4"
5
5
  end
6
6
  end
7
7
  end
@@ -28,8 +28,9 @@ module Rails
28
28
  # If not, attributes are removed based on Loofahs +HTML5::Scrub.scrub_attributes+.
29
29
  #
30
30
  # class CommentScrubber < Html::PermitScrubber
31
- # def allowed_node?(node)
32
- # !%w(form script comment blockquote).include?(node.name)
31
+ # def initialize
32
+ # super
33
+ # self.tags = %w(form script comment blockquote)
33
34
  # end
34
35
  #
35
36
  # def skip_node?(node)
@@ -152,6 +153,8 @@ module Rails
152
153
  end
153
154
 
154
155
  node.remove_attribute(attr_node.name) if attr_name == 'src' && attr_node.value !~ /[^[:space:]]/
156
+
157
+ Loofah::HTML5::Scrub.force_correct_attribute_escaping! node
155
158
  end
156
159
  end
157
160
 
@@ -33,7 +33,7 @@ class SanitizersTest < Minitest::Test
33
33
  assert_equal %(<h1>hello </h1>), xpath_sanitize(html, xpaths: %w(.//script))
34
34
  end
35
35
 
36
- def test_remove_xpaths_removes_all_occurences_of_xpath
36
+ def test_remove_xpaths_removes_all_occurrences_of_xpath
37
37
  html = %(<section><header><script>code!</script></header><p>hello <script>code!</script></p></section>)
38
38
  assert_equal %(<section><header></header><p>hello </p></section>), xpath_sanitize(html, xpaths: %w(.//script))
39
39
  end
@@ -58,11 +58,11 @@ class SanitizersTest < Minitest::Test
58
58
  end
59
59
 
60
60
  def test_strip_invalid_html
61
- assert_equal "", full_sanitize("<<<bad html")
61
+ assert_equal "&lt;&lt;", full_sanitize("<<<bad html")
62
62
  end
63
63
 
64
64
  def test_strip_nested_tags
65
- expected = "Weia onclick='alert(document.cookie);'/&gt;rdos"
65
+ expected = "Wei&lt;a onclick='alert(document.cookie);'/&gt;rdos"
66
66
  input = "Wei<<a>a onclick='alert(document.cookie);'</a>/>rdos"
67
67
  assert_equal expected, full_sanitize(input)
68
68
  end
@@ -74,7 +74,7 @@ class SanitizersTest < Minitest::Test
74
74
  assert_equal expected, full_sanitize(input)
75
75
  end
76
76
 
77
- def test_strip_comments
77
+ def test_remove_unclosed_tags
78
78
  assert_equal "This is ", full_sanitize("This is <-- not\n a comment here.")
79
79
  end
80
80
 
@@ -87,7 +87,9 @@ class SanitizersTest < Minitest::Test
87
87
  end
88
88
 
89
89
  def test_strip_blank_string
90
- [nil, '', ' '].each { |blank| assert_equal blank, full_sanitize(blank) }
90
+ assert_nil full_sanitize(nil)
91
+ assert_equal "", full_sanitize("")
92
+ assert_equal " ", full_sanitize(" ")
91
93
  end
92
94
 
93
95
  def test_strip_tags_with_plaintext
@@ -98,8 +100,8 @@ class SanitizersTest < Minitest::Test
98
100
  assert_equal "This is a test.", full_sanitize("<p>This <u>is<u> a <a href='test.html'><strong>test</strong></a>.</p>")
99
101
  end
100
102
 
101
- def test_strip_tags_with_many_open_quotes
102
- assert_equal "", full_sanitize("<<<bad html>")
103
+ def test_escape_tags_with_many_open_quotes
104
+ assert_equal "&lt;&lt;", full_sanitize("<<<bad html>")
103
105
  end
104
106
 
105
107
  def test_strip_tags_with_sentence
@@ -123,7 +125,7 @@ class SanitizersTest < Minitest::Test
123
125
  end
124
126
 
125
127
  def test_strip_links_with_tags_in_tags
126
- expected = "a href='hello'&gt;all <b>day</b> long/a&gt;"
128
+ expected = "&lt;a href='hello'&gt;all <b>day</b> long&lt;/a&gt;"
127
129
  input = "<<a>a href='hello'>all <b>day</b> long<</A>/a>"
128
130
  assert_equal expected, link_sanitize(input)
129
131
  end
@@ -360,7 +362,7 @@ class SanitizersTest < Minitest::Test
360
362
  end
361
363
 
362
364
  def test_should_sanitize_script_tag_with_multiple_open_brackets
363
- assert_sanitized %(<<SCRIPT>alert("XSS");//<</SCRIPT>), "alert(\"XSS\");//"
365
+ assert_sanitized %(<<SCRIPT>alert("XSS");//<</SCRIPT>), "&lt;alert(\"XSS\");//&lt;"
364
366
  assert_sanitized %(<iframe src=http://ha.ckers.org/scriptlet.html\n<a), ""
365
367
  end
366
368
 
@@ -383,13 +385,13 @@ class SanitizersTest < Minitest::Test
383
385
 
384
386
  def test_should_sanitize_illegal_style_properties
385
387
  raw = %(display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;)
386
- expected = %(display: block; width: 100%; height: 100%; background-color: black; background-x: center; background-y: center;)
388
+ expected = %(display:block;width:100%;height:100%;background-color:black;background-x:center;background-y:center;)
387
389
  assert_equal expected, sanitize_css(raw)
388
390
  end
389
391
 
390
392
  def test_should_sanitize_with_trailing_space
391
393
  raw = "display:block; "
392
- expected = "display: block;"
394
+ expected = "display:block;"
393
395
  assert_equal expected, sanitize_css(raw)
394
396
  end
395
397
 
@@ -482,6 +484,38 @@ class SanitizersTest < Minitest::Test
482
484
  assert_equal %(<a data-foo="foo">foo</a>), white_list_sanitize(text, attributes: ['data-foo'])
483
485
  end
484
486
 
487
+ def test_uri_escaping_of_href_attr_in_a_tag_in_white_list_sanitizer
488
+ html = %{<a href='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
489
+
490
+ text = white_list_sanitize(html)
491
+
492
+ assert_equal %{<a href="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
493
+ end
494
+
495
+ def test_uri_escaping_of_src_attr_in_a_tag_in_white_list_sanitizer
496
+ html = %{<a src='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
497
+
498
+ text = white_list_sanitize(html)
499
+
500
+ assert_equal %{<a src="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
501
+ end
502
+
503
+ def test_uri_escaping_of_name_attr_in_a_tag_in_white_list_sanitizer
504
+ html = %{<a name='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
505
+
506
+ text = white_list_sanitize(html)
507
+
508
+ assert_equal %{<a name="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
509
+ end
510
+
511
+ def test_uri_escaping_of_name_action_in_a_tag_in_white_list_sanitizer
512
+ html = %{<a action='examp<!--" unsafeattr=foo()>-->le.com'>test</a>}
513
+
514
+ text = white_list_sanitize(html, attributes: ['action'])
515
+
516
+ assert_equal %{<a action="examp<!--%22%20unsafeattr=foo()>-->le.com">test</a>}, text
517
+ end
518
+
485
519
  protected
486
520
 
487
521
  def xpath_sanitize(input, options = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-html-sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Mendonça França
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-25 00:00:00.000000000 Z
12
+ date: 2018-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: loofah
@@ -17,14 +17,20 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.0'
20
+ version: '2.2'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.2.2
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
28
  - - "~>"
26
29
  - !ruby/object:Gem::Version
27
- version: '2.0'
30
+ version: '2.2'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.2
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: bundler
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +96,7 @@ extensions: []
90
96
  extra_rdoc_files: []
91
97
  files:
92
98
  - CHANGELOG.md
99
+ - MIT-LICENSE
93
100
  - README.md
94
101
  - lib/rails-html-sanitizer.rb
95
102
  - lib/rails/html/sanitizer.rb
@@ -117,10 +124,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
124
  version: '0'
118
125
  requirements: []
119
126
  rubyforge_project:
120
- rubygems_version: 2.5.1
127
+ rubygems_version: 2.7.6
121
128
  signing_key:
122
129
  specification_version: 4
123
130
  summary: This gem is responsible to sanitize HTML fragments in Rails applications.
124
131
  test_files:
125
- - test/sanitizer_test.rb
126
132
  - test/scrubbers_test.rb
133
+ - test/sanitizer_test.rb