gon 4.1.0 → 4.1.1

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

Potentially problematic release.


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

@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 4.1.1
4
+
5
+ * Fixed critical XSS vulnerability https://github.com/gazay/gon/issues/84 (@vadimr & @Hebo)
6
+
3
7
  ## 4.1.0
4
8
 
5
9
  * Refactored script tag generation (@toothrot)
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Gon. You should try this. If you look closer - you will see an elephant.](https://github.com/gazay/gon/raw/master/doc/logo_small.png)
4
4
 
5
- ### Build Status [![Build Status](https://secure.travis-ci.org/gazay/gon.png)](http://travis-ci.org/gazay/gon)
5
+ [![Build Status](https://secure.travis-ci.org/gazay/gon.png)](http://travis-ci.org/gazay/gon) [![CodeClimate](https://codeclimate.com/github/gazay/gon.png)](https://codeclimate.com/github/gazay/gon)
6
6
 
7
7
  If you need to send some data to your js files and you don't want to do this with long way through views and parsing - use this force!
8
8
 
@@ -3,24 +3,13 @@ class Gon
3
3
  class << self
4
4
 
5
5
  def render_data(options)
6
- data = Gon.all_variables || {}
7
- if Gon.global.all_variables.present?
8
- data[:global] = Gon.global.all_variables
9
- end
10
6
  namespace, tag, cameled, watch = parse_options options
11
7
  script = "window.#{namespace} = {};"
12
8
 
13
- data.each do |key, val|
14
- if cameled
15
- script << "#{namespace}.#{key.to_s.camelize(:lower)}=#{val.to_json};"
16
- else
17
- script << "#{namespace}.#{key.to_s}=#{val.to_json};"
18
- end
19
- end
20
-
21
- script << Gon.watch.render if watch and Gon::Watch.all_variables.present?
9
+ script << formatted_data(namespace, cameled, watch)
22
10
  script = Gon::Escaper.escape_unicode(script)
23
11
  script = Gon::Escaper.javascript_tag(script) if tag
12
+
24
13
  script.html_safe
25
14
  end
26
15
 
@@ -58,6 +47,31 @@ class Gon
58
47
  [namespace, tag, cameled, watch]
59
48
  end
60
49
 
50
+ def formatted_data(namespace, keys_cameled, watch)
51
+ script = ''
52
+
53
+ gon_variables.each do |key, val|
54
+ js_key = keys_cameled ? key.to_s.camelize(:lower) : key.to_s
55
+ script << "#{namespace}.#{js_key}=#{val.to_json};"
56
+ end
57
+
58
+ if watch and Gon::Watch.all_variables.present?
59
+ script << Gon.watch.render
60
+ end
61
+
62
+ script
63
+ end
64
+
65
+ def gon_variables
66
+ data = Gon.all_variables || {}
67
+
68
+ if Gon.global.all_variables.present?
69
+ data[:global] = Gon.global.all_variables
70
+ end
71
+
72
+ data
73
+ end
74
+
61
75
  def right_extension?(extension, template_path)
62
76
  File.extname(template_path) == ".#{extension}"
63
77
  end
@@ -7,7 +7,7 @@ class Gon
7
7
 
8
8
  def escape_unicode(javascript)
9
9
  if javascript
10
- result = javascript.gsub(/\342\200\250/u, '&#x2028;')
10
+ result = javascript.gsub(/\342\200\250/u, '&#x2028;').gsub(/(<\/)/u, '\u003C/')
11
11
  javascript.html_safe? ? result.html_safe : result
12
12
  else
13
13
  ''
@@ -78,16 +78,20 @@ class Gon
78
78
  path = partial_line.match(/['"]([^'"]*)['"]/)[1]
79
79
  path = parse_path path
80
80
  options_hash = partial_line.match(/,(.*)/)[1]
81
- if options_hash.present?
82
- options = eval '{' + options_hash + '}'
83
- options.each do |name, val|
84
- self.instance_variable_set('@' + name.to_s, val)
85
- eval "def #{name}; self.instance_variable_get('@' + '#{name.to_s}'); end"
86
- end
87
- end
81
+
82
+ set_options_from_hash(options_hash) if options_hash.present?
83
+
88
84
  find_partials File.readlines(path)
89
85
  end
90
86
 
87
+ def set_options_from_hash(options_hash)
88
+ options = eval "{#{options_hash}}"
89
+ options.each do |name, val|
90
+ self.instance_variable_set("@#{name.to_s}", val)
91
+ eval "def #{name}; self.instance_variable_get('@' + '#{name.to_s}'); end"
92
+ end
93
+ end
94
+
91
95
  def parse_path(path)
92
96
  return path if File.exists?(path)
93
97
 
@@ -1,3 +1,3 @@
1
1
  class Gon
2
- VERSION = '4.1.0'
2
+ VERSION = '4.1.1'
3
3
  end
@@ -102,7 +102,7 @@ describe Gon do
102
102
  @base.include_gon.should == '<script type="text/javascript">' +
103
103
  "\n//<![CDATA[\n" +
104
104
  'window.gon = {};' +
105
- %q(gon.str="</script><script>alert('!')</script>";) +
105
+ %q(gon.str="\u003C/script><script>alert('!')\u003C/script>";) +
106
106
  "\n//]]>\n" +
107
107
  '</script>'
108
108
  end
@@ -83,7 +83,7 @@ describe Gon::Global do
83
83
  @base.include_gon.should == "<script type=\"text/javascript\">" +
84
84
  "\n//<![CDATA[\n" +
85
85
  "window.gon = {};" +
86
- "gon.global={\"str\":\"</script><script>alert('!')</script>\"};" +
86
+ "gon.global={\"str\":\"\\u003C/script><script>alert('!')\\u003C/script>\"};" +
87
87
  "\n//]]>\n" +
88
88
  "</script>"
89
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gon
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack