query_diet 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e714d7e589b1eb0c4b8b40c4fb3719fb2ea002d1
4
- data.tar.gz: 9b63133c9734edd60d207705ab3587a8fb2effec
2
+ SHA256:
3
+ metadata.gz: 17f9c2961a95f7d7c70c35ae50bc6f0e659bc3c746ddf519c65448cc9faefa98
4
+ data.tar.gz: 7f76be36042170e1e8d5aff0b066d552f9fff66f2ea5d31bffee3924e5e21368
5
5
  SHA512:
6
- metadata.gz: 0c488e7757fe3bd1ed06857994306b69c4daffa3335a1577502b5cda2d284195984242494f471385b0bdd431b637b84127442af07cadd2a4c963fd4fed663fb6
7
- data.tar.gz: 3bf7d7333153b318e90c67718e906e2952bef913b4e41b0778c72b0ffa66522c5c545ce145229869c34d5b59e527be125f9684daa8920e5e3cfc67f9cb16828a
6
+ metadata.gz: 17e90e9a4ec095f1c333f719226ec938d8f058526bdf14c2d731842cf1322057d3d14f35b279e0dd62b86600366b4318e8206852e104a71a25a0bc9dc323f309
7
+ data.tar.gz: 2c7d0bac77d92987974d9229535bff8b438e520c2b00ae71ef37206eef6d2d114ffa07515e5b67af5b78a08a103738fd588ae5c64f8f80dc00f373950dd1e583
data/README.md CHANGED
@@ -45,6 +45,25 @@ To change the default, simply pass them to the `query_diet_widget` helper:
45
45
  <%= query_diet_widget(:bad_count => 4, :bad_time => 2000) %>
46
46
  ```
47
47
 
48
+ ### Content Security Policy
49
+
50
+ You can pass whether to use a nonce for style and script tags.
51
+ Note that the key must be a symbol like in the example below, otherwise it defaults to `false`.
52
+
53
+ ```Erb
54
+ <%= query_diet_widget(:nonce => true) if Rails.env.development? %>
55
+ ```
56
+
57
+ In your content security policy initializer of the project you should set the nonce to those directives:
58
+ ```Erb
59
+ Rails.application.config.content_security_policy_nonce_directives = %w[script-src style-src]
60
+ ```
61
+
62
+ When you do not want to use a nonce, but use a style tag, for example, you could use `unsafe_inline`:
63
+ ```Erb
64
+ Rails.application.config.content_security_policy do |policy|
65
+ policy.style_src :self, :unsafe_inline
66
+ ```
48
67
 
49
68
  ### Rails compatibility
50
69
 
@@ -1,3 +1,3 @@
1
1
  module QueryDiet
2
- VERSION = '0.6.2'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -2,9 +2,9 @@ module QueryDiet
2
2
  module Widget
3
3
  class << self
4
4
 
5
- def css
5
+ def css(nonce_attribute)
6
6
  <<-EOF
7
- <style type="text/css"><!--
7
+ <style type="text/css"#{nonce_attribute}><!--
8
8
  div#query_diet {
9
9
  position: absolute;
10
10
  top: 0;
@@ -31,9 +31,19 @@ module QueryDiet
31
31
  EOF
32
32
  end
33
33
 
34
+ def js(nonce_attribute)
35
+ <<-EOF
36
+ <script type="text/javascript"#{nonce_attribute}>
37
+ document.getElementById("query_diet").addEventListener("click", function() {
38
+ this.parentNode.removeChild(this);
39
+ });
40
+ </script>
41
+ EOF
42
+ end
43
+
34
44
  def html(options)
35
45
  <<-EOF
36
- <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }" onclick="this.parentNode.removeChild(this);">
46
+ <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }">
37
47
  #{QueryDiet::Logger.count} / #{QueryDiet::Logger.time}ms
38
48
  </div>
39
49
  EOF
@@ -43,7 +53,12 @@ module QueryDiet
43
53
 
44
54
  module Helper
45
55
  def query_diet_widget(options = {})
46
- html = Widget.css + Widget.html(options)
56
+ default_html_options = {:nonce => false}
57
+ options = options.reverse_merge(default_html_options)
58
+
59
+ nonce_attribute = options.fetch(:nonce) ? " nonce=\"#{content_security_policy_nonce}\"" : ''
60
+
61
+ html = Widget.css(nonce_attribute) + Widget.html(options) + Widget.js(nonce_attribute)
47
62
  html.respond_to?(:html_safe) ? html.html_safe : html
48
63
  end
49
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_diet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-04 00:00:00.000000000 Z
12
+ date: 2020-09-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rails database query counter that stays out of your way
15
15
  email: github@makandra.de
@@ -44,8 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubyforge_project:
48
- rubygems_version: 2.4.5.1
47
+ rubygems_version: 3.1.3
49
48
  signing_key:
50
49
  specification_version: 4
51
50
  summary: Rails database query counter that stays out of your way