sanitize 3.0.4 → 3.1.0

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba375648ad289cc08ce45eafc47ed464ce6e7f9e
4
- data.tar.gz: 88022411ca58369ad7f0699f022c67c344891e69
3
+ metadata.gz: 590de6883d3b0fe07e34fa62416a586e178146ff
4
+ data.tar.gz: b759297e620f13b37dd322c295c2dbfc974581b8
5
5
  SHA512:
6
- metadata.gz: 24abf590a86b592353ca6b5602afef29c30b1063a5bb1c907bd9a51d6ee6962a2a733abd7b4ef8923aee0221eb2c3935221615c9f257363a1cc0cae906e34026
7
- data.tar.gz: 4b18f5dd27ccb560f96189eb081ab100d33604c87e08f7d24ce183b5cc5c5b58f6848a30d3aad51e9cffd3228c9baa6f4090ea185d6aaee0f2f55fb253069f42
6
+ metadata.gz: e6844945a3a4de69cb1c8e91ae8134598b9757a39defc27a3390c34569129a2b0adeff04b403f51778fdcca3212e7d4d7f3586e10250f61b1f0894c1e5c8a13c
7
+ data.tar.gz: ba68e2d5e5145a3610248a16c988aac7e0f129d252c04dc1db8c2b562acac36f1c1bcb6db70516eae2d801d6dba0d110732df72b62a71445ab66deef9e7f80ef
data/HISTORY.md CHANGED
@@ -1,6 +1,24 @@
1
1
  Sanitize History
2
2
  ================================================================================
3
3
 
4
+ Version 3.1.0 (2013-12-22)
5
+ --------------------------
6
+
7
+ * Added the following CSS properties to the relaxed config. [@ehudc - #120][120]
8
+
9
+ - `-moz-text-size-adjust`
10
+ - `-ms-text-size-adjust`
11
+ - `-webkit-text-size-adjust`
12
+ - `text-size-adjust`
13
+
14
+ * Updated Nokogumbo to 1.2.0 to pick up a fix for a Gumbo bug where the
15
+ entity `Æ` left its semicolon behind when it was converted to a
16
+ character during parsing. [#119][119]
17
+
18
+ [119]:https://github.com/rgrove/sanitize/issues/119
19
+ [120]:https://github.com/rgrove/sanitize/pull/120
20
+
21
+
4
22
  Version 3.0.4 (2014-12-12)
5
23
  --------------------------
6
24
 
@@ -62,6 +62,7 @@ class Sanitize
62
62
  -moz-text-decoration-color
63
63
  -moz-text-decoration-line
64
64
  -moz-text-decoration-style
65
+ -moz-text-size-adjust
65
66
  -ms-background-position-x
66
67
  -ms-background-position-y
67
68
  -ms-block-progression
@@ -132,6 +133,7 @@ class Sanitize
132
133
  -ms-text-justify
133
134
  -ms-text-kashida-space
134
135
  -ms-text-overflow
136
+ -ms-text-size-adjust
135
137
  -ms-text-underline-position
136
138
  -ms-touch-action
137
139
  -ms-user-select
@@ -300,6 +302,7 @@ class Sanitize
300
302
  -webkit-text-decoration-color
301
303
  -webkit-text-decoration-line
302
304
  -webkit-text-decoration-style
305
+ -webkit-text-size-adjust
303
306
  -webkit-touch-callout
304
307
  -webkit-transform
305
308
  -webkit-transform-origin
@@ -495,6 +498,7 @@ class Sanitize
495
498
  text-overflow
496
499
  text-rendering
497
500
  text-shadow
501
+ text-size-adjust
498
502
  text-transform
499
503
  text-underline-position
500
504
  top
@@ -106,20 +106,34 @@ class Sanitize; class CSS
106
106
  #
107
107
  # @return [Array] Sanitized Crass CSS parse tree.
108
108
  def tree!(tree)
109
+ preceded_by_property = false
110
+
109
111
  tree.map! do |node|
110
112
  next nil if node.nil?
111
113
 
112
114
  case node[:node]
113
115
  when :at_rule
116
+ preceded_by_property = false
114
117
  next at_rule!(node)
115
118
 
116
119
  when :comment
117
120
  next node if @config[:allow_comments]
118
121
 
119
122
  when :property
120
- next property!(node)
123
+ prop = property!(node)
124
+ preceded_by_property = !prop.nil?
125
+ next prop
126
+
127
+ when :semicolon
128
+ # Only preserve the semicolon if it was preceded by a whitelisted
129
+ # property. Otherwise, omit it in order to prevent redundant semicolons.
130
+ if preceded_by_property
131
+ preceded_by_property = false
132
+ next node
133
+ end
121
134
 
122
135
  when :style_rule
136
+ preceded_by_property = false
123
137
  tree!(node[:children])
124
138
  next node
125
139
 
@@ -143,21 +157,18 @@ class Sanitize; class CSS
143
157
  return nil unless @config[:at_rules].include?(name)
144
158
 
145
159
  if AT_RULES_WITH_STYLES.include?(name)
146
- # Remove the { and } tokens surrounding the @media block.
147
- tokens = rule[:block][:tokens][1...-1]
148
-
149
- styles = Crass::Parser.parse_rules(tokens,
160
+ styles = Crass::Parser.parse_rules(rule[:block],
150
161
  :preserve_comments => @config[:allow_comments],
151
162
  :preserve_hacks => @config[:allow_hacks])
152
163
 
153
- rule[:block][:value] = tree!(styles)
164
+ rule[:block] = tree!(styles)
154
165
 
155
166
  elsif AT_RULES_WITH_PROPERTIES.include?(name)
156
- props = Crass::Parser.parse_properties(rule[:block][:value],
167
+ props = Crass::Parser.parse_properties(rule[:block],
157
168
  :preserve_comments => @config[:allow_comments],
158
169
  :preserve_hacks => @config[:allow_hacks])
159
170
 
160
- rule[:block][:value] = tree!(props)
171
+ rule[:block] = tree!(props)
161
172
 
162
173
  else
163
174
  rule.delete(:block)
@@ -186,29 +197,30 @@ class Sanitize; class CSS
186
197
 
187
198
  case child[:node]
188
199
  when :ident
189
- combined_value << value if String === value
200
+ combined_value << value.downcase if String === value
190
201
 
191
202
  when :function
192
203
  if child.key?(:name)
193
- return nil if child[:name].downcase == 'expression'
204
+ name = child[:name].downcase
205
+
206
+ if name == 'url'
207
+ return nil unless valid_url?(child)
208
+ end
209
+
210
+ combined_value << name
211
+ return nil if name == 'expression' || combined_value == 'expression'
194
212
  end
195
213
 
196
214
  if Array === value
197
215
  nodes.concat(value)
198
216
  elsif String === value
199
- combined_value << value
200
-
201
- if value.downcase == 'expression' || combined_value.downcase == 'expression'
202
- return nil
203
- end
217
+ lowercase_value = value.downcase
218
+ combined_value << lowercase_value
219
+ return nil if lowercase_value == 'expression' || combined_value == 'expression'
204
220
  end
205
221
 
206
222
  when :url
207
- if value =~ Sanitize::REGEX_PROTOCOL
208
- return nil unless @config[:protocols].include?($1.downcase)
209
- else
210
- return nil unless @config[:protocols].include?(:relative)
211
- end
223
+ return nil unless valid_url?(child)
212
224
 
213
225
  when :bad_url
214
226
  return nil
@@ -218,4 +230,54 @@ class Sanitize; class CSS
218
230
  prop
219
231
  end
220
232
 
233
+ # Returns `true` if the given node (which may be of type `:url` or
234
+ # `:function`, since the CSS syntax can produce both) uses a whitelisted
235
+ # protocol.
236
+ def valid_url?(node)
237
+ type = node[:node]
238
+
239
+ if type == :function
240
+ return false unless node.key?(:name) && node[:name].downcase == 'url'
241
+ return false unless Array === node[:value]
242
+
243
+ # A URL function's `:value` should be an array containing no more than one
244
+ # `:string` node and any number of `:whitespace` nodes.
245
+ #
246
+ # If it contains more than one `:string` node, or if it contains any other
247
+ # nodes except `:whitespace` nodes, it's not valid.
248
+ url_string_node = nil
249
+
250
+ node[:value].each do |token|
251
+ return false unless Hash === token
252
+
253
+ case token[:node]
254
+ when :string
255
+ return false unless url_string_node.nil?
256
+ url_string_node = token
257
+
258
+ when :whitespace
259
+ next
260
+
261
+ else
262
+ return false
263
+ end
264
+ end
265
+
266
+ return false if url_string_node.nil?
267
+ url = url_string_node[:value]
268
+ elsif type == :url
269
+ url = node[:value]
270
+ else
271
+ return false
272
+ end
273
+
274
+ if url =~ Sanitize::REGEX_PROTOCOL
275
+ return @config[:protocols].include?($1.downcase)
276
+ else
277
+ return @config[:protocols].include?(:relative)
278
+ end
279
+
280
+ false
281
+ end
282
+
221
283
  end; end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Sanitize
4
- VERSION = '3.0.4'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanitize
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Grove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2014-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: crass
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 1.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.1.12
47
+ version: 1.2.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.1.12
54
+ version: 1.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: 1.2.0
166
166
  requirements: []
167
167
  rubyforge_project:
168
- rubygems_version: 2.4.5
168
+ rubygems_version: 2.2.2
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Whitelist-based HTML and CSS sanitizer.