chartkick 3.1.0 → 3.2.0

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a982e8c986d3bfdf50bc533ccd2f4530a364a6155362b1d5ffa7217831be045c
4
- data.tar.gz: 97a4e2f859c84942009fd98995ccbcf26b8c28d5c56a88727599c51a07f36352
3
+ metadata.gz: 7b6eb4f5b6f498a122e58ca1dd4cf7e3e1f5d610e19faa5a702291e422549026
4
+ data.tar.gz: ec143cc0f819cdd1ccd955f43425d992daa87052aeede53f563beda9bace04a5
5
5
  SHA512:
6
- metadata.gz: cb7b936da97bd3bef92748667af865c21944759d14b7d95ae8c0b03f576502b85107ff866f538166c159ca0f23ad33390f9583d574bb672d1d49385369422ae8
7
- data.tar.gz: 5cb58d1991fb3ad47d8ac2b3a90b78d9292a1ad82dada7ad27ee112039b41de5427ae794e5ddcf7a7260af6aadcf0e80be60587b4b42883ca927cb7dabcbcdae
6
+ metadata.gz: 1a494948bc4eeb5c1567e82777601982d7f3f90bfeb5c8b8b29335620cc0eaac7659a8b91e72fe9672d29a3b580b2c512fd0524c553be2de9fb57b4dcfa27b7a
7
+ data.tar.gz: 9f2e116c8c529e744e078b368ece8aebd7235dec00aa297a0745f309a494e57a2e29b2243dd5873d159a4346be0ee331f1df474f2a4166133a8a9e6159a0e9d7
@@ -1,3 +1,7 @@
1
+ ## 3.2.0
2
+
3
+ - Fixed XSS vulnerability - see [#488](https://github.com/ankane/chartkick/issues/488)
4
+
1
5
  ## 3.1.0
2
6
 
3
7
  - Updated Chartkick.js to 3.1.0
data/README.md CHANGED
@@ -29,8 +29,6 @@ require("chartkick")
29
29
  require("chart.js")
30
30
  ```
31
31
 
32
- > You can also use `import` instead of `require()`
33
-
34
32
  For Rails 5 / Sprockets, in `app/assets/javascripts/application.js`, add:
35
33
 
36
34
  ```js
@@ -148,7 +146,7 @@ Min and max values
148
146
 
149
147
  `min` defaults to 0 for charts with non-negative values. Use `nil` to let the charting library decide.
150
148
 
151
- Min and max for x-axis - *Chart.js* [master]
149
+ Min and max for x-axis - *Chart.js*
152
150
 
153
151
  ```erb
154
152
  <%= line_chart data, xmin: "2018-01-01", xmax: "2019-01-01" %>
@@ -61,9 +61,29 @@ module Chartkick
61
61
  end
62
62
  nonce_html = nonce ? " nonce=\"#{ERB::Util.html_escape(nonce)}\"" : nil
63
63
 
64
- html = (options.delete(:html) || %(<div id="%{id}" style="height: %{height}; width: %{width}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>)) % {id: ERB::Util.html_escape(element_id), height: ERB::Util.html_escape(height), width: ERB::Util.html_escape(width)}
64
+ # html vars
65
+ html_vars = {
66
+ id: element_id,
67
+ height: height,
68
+ width: width
69
+ }
70
+ html_vars.each_key do |k|
71
+ html_vars[k] = ERB::Util.html_escape(html_vars[k])
72
+ end
73
+ html = (options.delete(:html) || %(<div id="%{id}" style="height: %{height}; width: %{width}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>)) % html_vars
74
+
75
+ # js vars
76
+ js_vars = {
77
+ type: klass, # don't convert to JSON, but still escape
78
+ id: element_id.to_json,
79
+ data: data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json,
80
+ options: options.to_json
81
+ }
82
+ js_vars.each_key do |k|
83
+ js_vars[k] = chartkick_json_escape(js_vars[k])
84
+ end
85
+ createjs = "new Chartkick.%{type}(%{id}, %{data}, %{options});" % js_vars
65
86
 
66
- createjs = "new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json}, #{options.to_json});"
67
87
  if defer
68
88
  js = <<JS
69
89
  <script type="text/javascript"#{nonce_html}>
@@ -105,5 +125,16 @@ JS
105
125
  end
106
126
  hash_a
107
127
  end
128
+
129
+ # from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/output_safety.rb
130
+ JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
131
+ JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
132
+ def chartkick_json_escape(s)
133
+ if ERB::Util.respond_to?(:json_escape)
134
+ ERB::Util.json_escape(s)
135
+ else
136
+ s.to_s.gsub(JSON_ESCAPE_REGEXP, JSON_ESCAPE)
137
+ end
138
+ end
108
139
  end
109
140
  end
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-26 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler