loofah 2.5.0 → 2.9.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.

@@ -7,21 +7,23 @@ module Loofah
7
7
  module Scrub
8
8
  CONTROL_CHARACTERS = /[`\u0000-\u0020\u007f\u0080-\u0101]/
9
9
  CSS_KEYWORDISH = /\A(#[0-9a-fA-F]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|-?\d{0,3}\.?\d{0,10}(ch|cm|r?em|ex|in|lh|mm|pc|pt|px|Q|vmax|vmin|vw|vh|%|,|\))?)\z/
10
- CRASS_SEMICOLON = { :node => :semicolon, :raw => ";" }
10
+ CRASS_SEMICOLON = { node: :semicolon, raw: ";" }
11
+ CSS_IMPORTANT = '!important'
12
+ CSS_PROPERTY_STRING_WITHOUT_EMBEDDED_QUOTES = /\A(["'])?[^"']+\1\z/
11
13
 
12
14
  class << self
13
15
  def allowed_element?(element_name)
14
- ::Loofah::HTML5::SafeList::ALLOWED_ELEMENTS_WITH_LIBXML2.include? element_name
16
+ ::Loofah::HTML5::SafeList::ALLOWED_ELEMENTS_WITH_LIBXML2.include?(element_name)
15
17
  end
16
18
 
17
19
  # alternative implementation of the html5lib attribute scrubbing algorithm
18
20
  def scrub_attributes(node)
19
21
  node.attribute_nodes.each do |attr_node|
20
22
  attr_name = if attr_node.namespace
21
- "#{attr_node.namespace.prefix}:#{attr_node.node_name}"
22
- else
23
- attr_node.node_name
24
- end
23
+ "#{attr_node.namespace.prefix}:#{attr_node.node_name}"
24
+ else
25
+ attr_node.node_name
26
+ end
25
27
 
26
28
  if attr_name =~ /\Adata-[\w-]+\z/
27
29
  next
@@ -57,13 +59,13 @@ module Loofah
57
59
  end
58
60
  end
59
61
 
60
- scrub_css_attribute node
62
+ scrub_css_attribute(node)
61
63
 
62
64
  node.attribute_nodes.each do |attr_node|
63
65
  node.remove_attribute(attr_node.name) if attr_node.value !~ /[^[:space:]]/
64
66
  end
65
67
 
66
- force_correct_attribute_escaping! node
68
+ force_correct_attribute_escaping!(node)
67
69
  end
68
70
 
69
71
  def scrub_css_attribute(node)
@@ -72,32 +74,54 @@ module Loofah
72
74
  end
73
75
 
74
76
  def scrub_css(style)
75
- style_tree = Crass.parse_properties style
77
+ style_tree = Crass.parse_properties(style)
76
78
  sanitized_tree = []
77
79
 
78
80
  style_tree.each do |node|
79
81
  next unless node[:node] == :property
80
82
  next if node[:children].any? do |child|
81
- [:url, :bad_url].include?(child[:node]) || (child[:node] == :function && !SafeList::ALLOWED_CSS_FUNCTIONS.include?(child[:name].downcase))
83
+ [:url, :bad_url].include?(child[:node])
82
84
  end
85
+
83
86
  name = node[:name].downcase
84
- if SafeList::ALLOWED_CSS_PROPERTIES.include?(name) || SafeList::ALLOWED_SVG_PROPERTIES.include?(name)
85
- sanitized_tree << node << CRASS_SEMICOLON
86
- elsif SafeList::SHORTHAND_CSS_PROPERTIES.include?(name.split("-").first)
87
- value = node[:value].split.map do |keyword|
88
- if SafeList::ALLOWED_CSS_KEYWORDS.include?(keyword) || keyword =~ CSS_KEYWORDISH
87
+ next unless SafeList::ALLOWED_CSS_PROPERTIES.include?(name) ||
88
+ SafeList::ALLOWED_SVG_PROPERTIES.include?(name) ||
89
+ SafeList::SHORTHAND_CSS_PROPERTIES.include?(name.split("-").first)
90
+
91
+ value = node[:children].map do |child|
92
+ case child[:node]
93
+ when :whitespace
94
+ nil
95
+ when :string
96
+ if child[:raw] =~ CSS_PROPERTY_STRING_WITHOUT_EMBEDDED_QUOTES
97
+ Crass::Parser.stringify(child)
98
+ else
99
+ nil
100
+ end
101
+ when :function
102
+ if SafeList::ALLOWED_CSS_FUNCTIONS.include?(child[:name].downcase)
103
+ Crass::Parser.stringify(child)
104
+ end
105
+ when :ident
106
+ keyword = child[:value]
107
+ if !SafeList::SHORTHAND_CSS_PROPERTIES.include?(name.split("-").first) ||
108
+ SafeList::ALLOWED_CSS_KEYWORDS.include?(keyword) ||
109
+ (keyword =~ CSS_KEYWORDISH)
89
110
  keyword
90
111
  end
91
- end.compact
92
- unless value.empty?
93
- propstring = sprintf "%s:%s", name, value.join(" ")
94
- sanitized_node = Crass.parse_properties(propstring).first
95
- sanitized_tree << sanitized_node << CRASS_SEMICOLON
112
+ else
113
+ child[:raw]
96
114
  end
97
- end
115
+ end.compact
116
+
117
+ next if value.empty?
118
+ value << CSS_IMPORTANT if node[:important]
119
+ propstring = format("%s:%s", name, value.join(" "))
120
+ sanitized_node = Crass.parse_properties(propstring).first
121
+ sanitized_tree << sanitized_node << CRASS_SEMICOLON
98
122
  end
99
123
 
100
- Crass::Parser.stringify sanitized_tree
124
+ Crass::Parser.stringify(sanitized_tree)
101
125
  end
102
126
 
103
127
  #
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ module Loofah
3
+ # The version of Loofah you are using
4
+ VERSION = "2.9.1"
5
+ 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.5.0
4
+ version: 2.9.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: 2020-04-05 00:00:00.000000000 Z
12
+ date: 2021-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -45,28 +45,28 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '12.3'
48
+ version: '13.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '12.3'
55
+ version: '13.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: minitest
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '2.2'
62
+ version: '5.14'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '2.2'
69
+ version: '5.14'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rr
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -87,98 +87,42 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 2.2.0
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: 2.2.0
98
- - !ruby/object:Gem::Dependency
99
- name: hoe-gemspec
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: '1.0'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: '1.0'
112
- - !ruby/object:Gem::Dependency
113
- name: hoe-debugging
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: '2.0'
90
+ version: '2.2'
119
91
  type: :development
120
92
  prerelease: false
121
93
  version_requirements: !ruby/object:Gem::Requirement
122
94
  requirements:
123
95
  - - "~>"
124
96
  - !ruby/object:Gem::Version
125
- version: '2.0'
97
+ version: '2.2'
126
98
  - !ruby/object:Gem::Dependency
127
- name: hoe-bundler
99
+ name: concourse
128
100
  requirement: !ruby/object:Gem::Requirement
129
101
  requirements:
130
102
  - - "~>"
131
103
  - !ruby/object:Gem::Version
132
- version: '1.5'
104
+ version: '0.33'
133
105
  type: :development
134
106
  prerelease: false
135
107
  version_requirements: !ruby/object:Gem::Requirement
136
108
  requirements:
137
109
  - - "~>"
138
110
  - !ruby/object:Gem::Version
139
- version: '1.5'
111
+ version: '0.33'
140
112
  - !ruby/object:Gem::Dependency
141
- name: hoe-git
113
+ name: rubocop
142
114
  requirement: !ruby/object:Gem::Requirement
143
115
  requirements:
144
116
  - - "~>"
145
117
  - !ruby/object:Gem::Version
146
- version: '1.6'
118
+ version: '1.1'
147
119
  type: :development
148
120
  prerelease: false
149
121
  version_requirements: !ruby/object:Gem::Requirement
150
122
  requirements:
151
123
  - - "~>"
152
124
  - !ruby/object:Gem::Version
153
- version: '1.6'
154
- - !ruby/object:Gem::Dependency
155
- name: concourse
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: 0.26.0
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: 0.26.0
168
- - !ruby/object:Gem::Dependency
169
- name: rubocop
170
- requirement: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - ">="
173
- - !ruby/object:Gem::Version
174
- version: 0.76.0
175
- type: :development
176
- prerelease: false
177
- version_requirements: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- version: 0.76.0
125
+ version: '1.1'
182
126
  - !ruby/object:Gem::Dependency
183
127
  name: rdoc
184
128
  requirement: !ruby/object:Gem::Requirement
@@ -200,19 +144,19 @@ dependencies:
200
144
  - !ruby/object:Gem::Version
201
145
  version: '7'
202
146
  - !ruby/object:Gem::Dependency
203
- name: hoe
147
+ name: hoe-markdown
204
148
  requirement: !ruby/object:Gem::Requirement
205
149
  requirements:
206
150
  - - "~>"
207
151
  - !ruby/object:Gem::Version
208
- version: '3.22'
152
+ version: '1.3'
209
153
  type: :development
210
154
  prerelease: false
211
155
  version_requirements: !ruby/object:Gem::Requirement
212
156
  requirements:
213
157
  - - "~>"
214
158
  - !ruby/object:Gem::Version
215
- version: '3.22'
159
+ version: '1.3'
216
160
  description: |-
217
161
  Loofah is a general library for manipulating and transforming HTML/XML documents and fragments, built on top of Nokogiri.
218
162
 
@@ -224,24 +168,12 @@ email:
224
168
  - bryan@brynary.com
225
169
  executables: []
226
170
  extensions: []
227
- extra_rdoc_files:
228
- - CHANGELOG.md
229
- - MIT-LICENSE.txt
230
- - Manifest.txt
231
- - README.md
232
- - SECURITY.md
171
+ extra_rdoc_files: []
233
172
  files:
234
173
  - CHANGELOG.md
235
- - Gemfile
236
174
  - MIT-LICENSE.txt
237
- - Manifest.txt
238
175
  - README.md
239
- - Rakefile
240
176
  - SECURITY.md
241
- - benchmark/benchmark.rb
242
- - benchmark/fragment.html
243
- - benchmark/helper.rb
244
- - benchmark/www.slashdot.com.html
245
177
  - lib/loofah.rb
246
178
  - lib/loofah/elements.rb
247
179
  - lib/loofah/helpers.rb
@@ -254,6 +186,7 @@ files:
254
186
  - lib/loofah/metahelpers.rb
255
187
  - lib/loofah/scrubber.rb
256
188
  - lib/loofah/scrubbers.rb
189
+ - lib/loofah/version.rb
257
190
  - lib/loofah/xml/document.rb
258
191
  - lib/loofah/xml/document_fragment.rb
259
192
  homepage: https://github.com/flavorjones/loofah
@@ -261,14 +194,12 @@ licenses:
261
194
  - MIT
262
195
  metadata:
263
196
  homepage_uri: https://github.com/flavorjones/loofah
197
+ source_code_uri: https://github.com/flavorjones/loofah
264
198
  bug_tracker_uri: https://github.com/flavorjones/loofah/issues
199
+ changelog_uri: https://github.com/flavorjones/loofah/blob/main/CHANGELOG.md
265
200
  documentation_uri: https://www.rubydoc.info/gems/loofah/
266
- changelog_uri: https://github.com/flavorjones/loofah/master/CHANGELOG.md
267
- source_code_uri: https://github.com/flavorjones/loofah
268
201
  post_install_message:
269
- rdoc_options:
270
- - "--main"
271
- - README.md
202
+ rdoc_options: []
272
203
  require_paths:
273
204
  - lib
274
205
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -282,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
213
  - !ruby/object:Gem::Version
283
214
  version: '0'
284
215
  requirements: []
285
- rubygems_version: 3.1.2
216
+ rubygems_version: 3.1.4
286
217
  signing_key:
287
218
  specification_version: 4
288
219
  summary: Loofah is a general library for manipulating and transforming HTML/XML documents
data/Gemfile DELETED
@@ -1,23 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- # DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4
-
5
- source "https://rubygems.org/"
6
-
7
- gem "nokogiri", ">=1.5.9"
8
- gem "crass", "~>1.0.2"
9
-
10
- gem "rake", "~>12.3", :group => [:development, :test]
11
- gem "minitest", "~>2.2", :group => [:development, :test]
12
- gem "rr", "~>1.2.0", :group => [:development, :test]
13
- gem "json", "~>2.2.0", :group => [:development, :test]
14
- gem "hoe-gemspec", "~>1.0", :group => [:development, :test]
15
- gem "hoe-debugging", "~>2.0", :group => [:development, :test]
16
- gem "hoe-bundler", "~>1.5", :group => [:development, :test]
17
- gem "hoe-git", "~>1.6", :group => [:development, :test]
18
- gem "concourse", ">=0.26.0", :group => [:development, :test]
19
- gem "rubocop", ">=0.76.0", :group => [:development, :test]
20
- gem "rdoc", ">=4.0", "<7", :group => [:development, :test]
21
- gem "hoe", "~>3.20", :group => [:development, :test]
22
-
23
- # vim: syntax=ruby
data/Manifest.txt DELETED
@@ -1,25 +0,0 @@
1
- CHANGELOG.md
2
- Gemfile
3
- MIT-LICENSE.txt
4
- Manifest.txt
5
- README.md
6
- Rakefile
7
- SECURITY.md
8
- benchmark/benchmark.rb
9
- benchmark/fragment.html
10
- benchmark/helper.rb
11
- benchmark/www.slashdot.com.html
12
- lib/loofah.rb
13
- lib/loofah/elements.rb
14
- lib/loofah/helpers.rb
15
- lib/loofah/html/document.rb
16
- lib/loofah/html/document_fragment.rb
17
- lib/loofah/html5/libxml2_workarounds.rb
18
- lib/loofah/html5/safelist.rb
19
- lib/loofah/html5/scrub.rb
20
- lib/loofah/instance_methods.rb
21
- lib/loofah/metahelpers.rb
22
- lib/loofah/scrubber.rb
23
- lib/loofah/scrubbers.rb
24
- lib/loofah/xml/document.rb
25
- lib/loofah/xml/document_fragment.rb
data/Rakefile DELETED
@@ -1,97 +0,0 @@
1
- require "rubygems"
2
- require "hoe"
3
- require "concourse"
4
-
5
- Hoe.plugin :git
6
- Hoe.plugin :gemspec
7
- Hoe.plugin :bundler
8
- Hoe.plugin :debugging
9
-
10
- Hoe.spec "loofah" do
11
- developer "Mike Dalessio", "mike.dalessio@gmail.com"
12
- developer "Bryan Helmkamp", "bryan@brynary.com"
13
-
14
- self.history_file = "CHANGELOG.md"
15
- self.readme_file = "README.md"
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
- }
24
-
25
- extra_deps << ["nokogiri", ">=1.5.9"]
26
- extra_deps << ["crass", "~> 1.0.2"]
27
-
28
- extra_dev_deps << ["rake", "~> 12.3"]
29
- extra_dev_deps << ["minitest", "~>2.2"]
30
- extra_dev_deps << ["rr", "~>1.2.0"]
31
- extra_dev_deps << ["json", "~> 2.2.0"]
32
- extra_dev_deps << ["hoe-gemspec", "~> 1.0"]
33
- extra_dev_deps << ["hoe-debugging", "~> 2.0"]
34
- extra_dev_deps << ["hoe-bundler", "~> 1.5"]
35
- extra_dev_deps << ["hoe-git", "~> 1.6"]
36
- extra_dev_deps << ["concourse", ">=0.26.0"]
37
- extra_dev_deps << ["rubocop", ">=0.76.0"]
38
- end
39
-
40
- task :gemspec do
41
- system %q(rake debug_gem | grep -v "^\(in " > loofah.gemspec)
42
- end
43
-
44
- task :redocs => :fix_css
45
- task :docs => :fix_css
46
- task :fix_css do
47
- better_css = <<-EOT
48
- .method-description pre {
49
- margin : 1em 0 ;
50
- }
51
-
52
- .method-description ul {
53
- padding : .5em 0 .5em 2em ;
54
- }
55
-
56
- .method-description p {
57
- margin-top : .5em ;
58
- }
59
-
60
- #main ul, div#documentation ul {
61
- list-style-type : disc ! IMPORTANT ;
62
- list-style-position : inside ! IMPORTANT ;
63
- }
64
-
65
- h2 + ul {
66
- margin-top : 1em;
67
- }
68
- EOT
69
- puts "* fixing css"
70
- File.open("doc/rdoc.css", "a") { |f| f.write better_css }
71
- end
72
-
73
- desc "generate and upload docs to rubyforge"
74
- task :doc_upload_to_rubyforge => :docs do
75
- Dir.chdir "doc" do
76
- system "rsync -avz --delete * rubyforge.org:/var/www/gforge-projects/loofah/loofah"
77
- end
78
- end
79
-
80
- desc "generate safelists from W3C specifications"
81
- task :generate_safelists do
82
- load "tasks/generate-safelists"
83
- end
84
-
85
- task :rubocop => [:rubocop_security, :rubocop_frozen_string_literals]
86
- task :rubocop_security do
87
- sh "rubocop lib --only Security"
88
- end
89
- task :rubocop_frozen_string_literals do
90
- sh "rubocop lib --auto-correct --only Style/FrozenStringLiteralComment"
91
- end
92
- Rake::Task[:test].prerequisites << :rubocop
93
-
94
- Concourse.new("loofah", fly_target: "ci") do |c|
95
- c.add_pipeline "loofah", "loofah.yml"
96
- c.add_pipeline "loofah-pr", "loofah-pr.yml"
97
- end