sanitize 6.1.3 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{HISTORY.md → CHANGELOG.md} +50 -14
- data/LICENSE +3 -1
- data/README.md +130 -239
- data/lib/sanitize/config/basic.rb +15 -15
- data/lib/sanitize/config/default.rb +45 -45
- data/lib/sanitize/config/relaxed.rb +136 -32
- data/lib/sanitize/config/restricted.rb +2 -2
- data/lib/sanitize/config.rb +12 -14
- data/lib/sanitize/css.rb +403 -308
- data/lib/sanitize/transformers/clean_cdata.rb +9 -9
- data/lib/sanitize/transformers/clean_comment.rb +9 -9
- data/lib/sanitize/transformers/clean_css.rb +59 -55
- data/lib/sanitize/transformers/clean_doctype.rb +15 -15
- data/lib/sanitize/transformers/clean_element.rb +219 -237
- data/lib/sanitize/version.rb +3 -1
- data/lib/sanitize.rb +38 -38
- metadata +15 -56
- data/test/common.rb +0 -3
- data/test/test_clean_comment.rb +0 -47
- data/test/test_clean_css.rb +0 -67
- data/test/test_clean_doctype.rb +0 -71
- data/test/test_clean_element.rb +0 -552
- data/test/test_config.rb +0 -65
- data/test/test_malicious_css.rb +0 -55
- data/test/test_malicious_html.rb +0 -339
- data/test/test_parser.rb +0 -75
- data/test/test_sanitize.rb +0 -197
- data/test/test_sanitize_css.rb +0 -433
- data/test/test_transformers.rb +0 -230
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sanitize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 7.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Grove
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: crass
|
|
@@ -16,65 +15,38 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.0.
|
|
18
|
+
version: 1.0.8
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.0.
|
|
25
|
+
version: 1.0.8
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: nokogiri
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
30
|
- - ">="
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 1.
|
|
32
|
+
version: 1.16.8
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - ">="
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 1.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '5.15'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '5.15'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rake
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: 13.0.6
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: 13.0.6
|
|
69
|
-
description: Sanitize is an allowlist-based HTML and CSS sanitizer. It removes all
|
|
70
|
-
HTML and/or CSS from a string except the elements, attributes, and properties you
|
|
39
|
+
version: 1.16.8
|
|
40
|
+
description: |
|
|
41
|
+
Sanitize is an allowlist-based HTML and CSS sanitizer. It removes all HTML
|
|
42
|
+
and/or CSS from a string except the elements, attributes, and properties you
|
|
71
43
|
choose to allow.
|
|
72
44
|
email: ryan@wonko.com
|
|
73
45
|
executables: []
|
|
74
46
|
extensions: []
|
|
75
47
|
extra_rdoc_files: []
|
|
76
48
|
files:
|
|
77
|
-
-
|
|
49
|
+
- CHANGELOG.md
|
|
78
50
|
- LICENSE
|
|
79
51
|
- README.md
|
|
80
52
|
- lib/sanitize.rb
|
|
@@ -90,25 +62,13 @@ files:
|
|
|
90
62
|
- lib/sanitize/transformers/clean_doctype.rb
|
|
91
63
|
- lib/sanitize/transformers/clean_element.rb
|
|
92
64
|
- lib/sanitize/version.rb
|
|
93
|
-
- test/common.rb
|
|
94
|
-
- test/test_clean_comment.rb
|
|
95
|
-
- test/test_clean_css.rb
|
|
96
|
-
- test/test_clean_doctype.rb
|
|
97
|
-
- test/test_clean_element.rb
|
|
98
|
-
- test/test_config.rb
|
|
99
|
-
- test/test_malicious_css.rb
|
|
100
|
-
- test/test_malicious_html.rb
|
|
101
|
-
- test/test_parser.rb
|
|
102
|
-
- test/test_sanitize.rb
|
|
103
|
-
- test/test_sanitize_css.rb
|
|
104
|
-
- test/test_transformers.rb
|
|
105
65
|
homepage: https://github.com/rgrove/sanitize/
|
|
106
66
|
licenses:
|
|
107
67
|
- MIT
|
|
108
68
|
metadata:
|
|
109
|
-
changelog_uri: https://github.com/rgrove/sanitize/blob/main/
|
|
69
|
+
changelog_uri: https://github.com/rgrove/sanitize/blob/main/CHANGELOG.md
|
|
110
70
|
documentation_uri: https://rubydoc.info/github/rgrove/sanitize
|
|
111
|
-
|
|
71
|
+
rubygems_mfa_required: 'true'
|
|
112
72
|
rdoc_options: []
|
|
113
73
|
require_paths:
|
|
114
74
|
- lib
|
|
@@ -116,15 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
116
76
|
requirements:
|
|
117
77
|
- - ">="
|
|
118
78
|
- !ruby/object:Gem::Version
|
|
119
|
-
version:
|
|
79
|
+
version: 3.1.0
|
|
120
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
81
|
requirements:
|
|
122
82
|
- - ">="
|
|
123
83
|
- !ruby/object:Gem::Version
|
|
124
|
-
version:
|
|
84
|
+
version: '0'
|
|
125
85
|
requirements: []
|
|
126
|
-
rubygems_version:
|
|
127
|
-
signing_key:
|
|
86
|
+
rubygems_version: 4.0.20
|
|
128
87
|
specification_version: 4
|
|
129
88
|
summary: Allowlist-based HTML and CSS sanitizer.
|
|
130
89
|
test_files: []
|
data/test/common.rb
DELETED
data/test/test_clean_comment.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require_relative 'common'
|
|
3
|
-
|
|
4
|
-
describe 'Sanitize::Transformers::CleanComment' do
|
|
5
|
-
make_my_diffs_pretty!
|
|
6
|
-
parallelize_me!
|
|
7
|
-
|
|
8
|
-
describe 'when :allow_comments is false' do
|
|
9
|
-
before do
|
|
10
|
-
@s = Sanitize.new(:allow_comments => false, :elements => ['div'])
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'should remove comments' do
|
|
14
|
-
_(@s.fragment('foo <!-- comment --> bar')).must_equal 'foo bar'
|
|
15
|
-
_(@s.fragment('foo <!-- ')).must_equal 'foo '
|
|
16
|
-
_(@s.fragment('foo <!-- - -> bar')).must_equal 'foo '
|
|
17
|
-
_(@s.fragment("foo <!--\n\n\n\n-->bar")).must_equal 'foo bar'
|
|
18
|
-
_(@s.fragment("foo <!-- <!-- <!-- --> --> -->bar")).must_equal 'foo --> -->bar'
|
|
19
|
-
_(@s.fragment("foo <div <!-- comment -->>bar</div>")).must_equal 'foo <div>>bar</div>'
|
|
20
|
-
|
|
21
|
-
# Special case: the comment markup is inside a <script>, which makes it
|
|
22
|
-
# text content and not an actual HTML comment.
|
|
23
|
-
_(@s.fragment("<script><!-- comment --></script>")).must_equal ''
|
|
24
|
-
|
|
25
|
-
_(Sanitize.fragment("<script><!-- comment --></script>", :allow_comments => false, :elements => ['script']))
|
|
26
|
-
.must_equal '<script><!-- comment --></script>'
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe 'when :allow_comments is true' do
|
|
31
|
-
before do
|
|
32
|
-
@s = Sanitize.new(:allow_comments => true, :elements => ['div'])
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'should allow comments' do
|
|
36
|
-
_(@s.fragment('foo <!-- comment --> bar')).must_equal 'foo <!-- comment --> bar'
|
|
37
|
-
_(@s.fragment('foo <!-- ')).must_equal 'foo <!-- -->'
|
|
38
|
-
_(@s.fragment('foo <!-- - -> bar')).must_equal 'foo <!-- - -> bar-->'
|
|
39
|
-
_(@s.fragment("foo <!--\n\n\n\n-->bar")).must_equal "foo <!--\n\n\n\n-->bar"
|
|
40
|
-
_(@s.fragment("foo <!-- <!-- <!-- --> --> -->bar")).must_equal 'foo <!-- <!-- <!-- --> --> -->bar'
|
|
41
|
-
_(@s.fragment("foo <div <!-- comment -->>bar</div>")).must_equal 'foo <div>>bar</div>'
|
|
42
|
-
|
|
43
|
-
_(Sanitize.fragment("<script><!-- comment --></script>", :allow_comments => true, :elements => ['script']))
|
|
44
|
-
.must_equal '<script><!-- comment --></script>'
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
data/test/test_clean_css.rb
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require_relative 'common'
|
|
3
|
-
|
|
4
|
-
describe 'Sanitize::Transformers::CSS::CleanAttribute' do
|
|
5
|
-
make_my_diffs_pretty!
|
|
6
|
-
parallelize_me!
|
|
7
|
-
|
|
8
|
-
before do
|
|
9
|
-
@s = Sanitize.new(Sanitize::Config::RELAXED)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
it 'should sanitize CSS properties in style attributes' do
|
|
13
|
-
_(@s.fragment(%[
|
|
14
|
-
<div style="color: #fff; width: expression(alert(1)); /* <-- evil! */"></div>
|
|
15
|
-
].strip)).must_equal %[
|
|
16
|
-
<div style="color: #fff; /* <-- evil! */"></div>
|
|
17
|
-
].strip
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'should remove the style attribute if the sanitized CSS is empty' do
|
|
21
|
-
_(@s.fragment('<div style="width: expression(alert(1))"></div>')).
|
|
22
|
-
must_equal '<div></div>'
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
describe 'Sanitize::Transformers::CSS::CleanElement' do
|
|
27
|
-
make_my_diffs_pretty!
|
|
28
|
-
parallelize_me!
|
|
29
|
-
|
|
30
|
-
before do
|
|
31
|
-
@s = Sanitize.new(Sanitize::Config::RELAXED)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'should sanitize CSS stylesheets in <style> elements' do
|
|
35
|
-
html = %[
|
|
36
|
-
<style>@import url(evil.css);
|
|
37
|
-
/* Yay CSS! */
|
|
38
|
-
.foo { color: #fff; }
|
|
39
|
-
#bar { background: url(yay.jpg); bogus: wtf; }
|
|
40
|
-
.evil { width: expression(xss()); }
|
|
41
|
-
|
|
42
|
-
@media screen (max-width:480px) {
|
|
43
|
-
.foo { width: 400px; }
|
|
44
|
-
#bar:not(.baz) { height: 100px; }
|
|
45
|
-
}
|
|
46
|
-
</style>
|
|
47
|
-
].strip
|
|
48
|
-
|
|
49
|
-
_(@s.fragment(html)).must_equal %[
|
|
50
|
-
<style>
|
|
51
|
-
/* Yay CSS! */
|
|
52
|
-
.foo { color: #fff; }
|
|
53
|
-
#bar { background: url(yay.jpg); }
|
|
54
|
-
.evil { }
|
|
55
|
-
|
|
56
|
-
@media screen (max-width:480px) {
|
|
57
|
-
.foo { width: 400px; }
|
|
58
|
-
#bar:not(.baz) { height: 100px; }
|
|
59
|
-
}
|
|
60
|
-
</style>
|
|
61
|
-
].strip
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'should remove the <style> element if the sanitized CSS is empty' do
|
|
65
|
-
_(@s.fragment('<style></style>')).must_equal ''
|
|
66
|
-
end
|
|
67
|
-
end
|
data/test/test_clean_doctype.rb
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require_relative 'common'
|
|
3
|
-
|
|
4
|
-
describe 'Sanitize::Transformers::CleanDoctype' do
|
|
5
|
-
make_my_diffs_pretty!
|
|
6
|
-
parallelize_me!
|
|
7
|
-
|
|
8
|
-
describe 'when :allow_doctype is false' do
|
|
9
|
-
before do
|
|
10
|
-
@s = Sanitize.new(:allow_doctype => false, :elements => ['html'])
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'should remove doctype declarations' do
|
|
14
|
-
_(@s.document('<!DOCTYPE html><html>foo</html>')).must_equal "<html>foo</html>"
|
|
15
|
-
_(@s.fragment('<!DOCTYPE html>foo')).must_equal 'foo'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'should not allow doctype definitions in fragments' do
|
|
19
|
-
_(@s.fragment('<!DOCTYPE html><html>foo</html>'))
|
|
20
|
-
.must_equal "foo"
|
|
21
|
-
|
|
22
|
-
_(@s.fragment('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
|
|
23
|
-
.must_equal "foo"
|
|
24
|
-
|
|
25
|
-
_(@s.fragment("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html>foo</html>"))
|
|
26
|
-
.must_equal "foo"
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe 'when :allow_doctype is true' do
|
|
31
|
-
before do
|
|
32
|
-
@s = Sanitize.new(:allow_doctype => true, :elements => ['html'])
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'should allow doctype declarations in documents' do
|
|
36
|
-
_(@s.document('<!DOCTYPE html><html>foo</html>'))
|
|
37
|
-
.must_equal "<!DOCTYPE html><html>foo</html>"
|
|
38
|
-
|
|
39
|
-
_(@s.document('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
|
|
40
|
-
.must_equal "<!DOCTYPE html><html>foo</html>"
|
|
41
|
-
|
|
42
|
-
_(@s.document("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html>foo</html>"))
|
|
43
|
-
.must_equal "<!DOCTYPE html><html>foo</html>"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'should not allow obviously invalid doctype declarations in documents' do
|
|
47
|
-
_(@s.document('<!DOCTYPE blah blah blah><html>foo</html>'))
|
|
48
|
-
.must_equal "<!DOCTYPE html><html>foo</html>"
|
|
49
|
-
|
|
50
|
-
_(@s.document('<!DOCTYPE blah><html>foo</html>'))
|
|
51
|
-
.must_equal "<!DOCTYPE html><html>foo</html>"
|
|
52
|
-
|
|
53
|
-
_(@s.document('<!DOCTYPE html BLAH "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
|
|
54
|
-
.must_equal "<!DOCTYPE html><html>foo</html>"
|
|
55
|
-
|
|
56
|
-
_(@s.document('<!whatever><html>foo</html>'))
|
|
57
|
-
.must_equal "<html>foo</html>"
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'should not allow doctype definitions in fragments' do
|
|
61
|
-
_(@s.fragment('<!DOCTYPE html><html>foo</html>'))
|
|
62
|
-
.must_equal "foo"
|
|
63
|
-
|
|
64
|
-
_(@s.fragment('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html>foo</html>'))
|
|
65
|
-
.must_equal "foo"
|
|
66
|
-
|
|
67
|
-
_(@s.fragment("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html>foo</html>"))
|
|
68
|
-
.must_equal "foo"
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|