secure_headers 6.6.0 → 6.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
2
  SHA256:
3
- metadata.gz: 2afd142dc54275ace387af0a964bba3918655513474a14f11959532616108d58
4
- data.tar.gz: f520ab4f191710af2d78bc662319b02ab7819bba57a091c921822984393f18e5
3
+ metadata.gz: 6919954e57f87c70a4fa42baa5285649bd7484ec6785894a2b461b6f52558f29
4
+ data.tar.gz: 710492a0e64a47f41f2b079e6d4799922aa05e51d017cacafcc20d77383815ee
5
5
  SHA512:
6
- metadata.gz: 3fe9df12ae44cabd372f84e8eebd47946e6102d8c920cf48752e3f36bcd1db3e429cbc47e54dda8f8194b4ae2cb90c583eec38b0e7906bac8f0fb9337eb7ecad
7
- data.tar.gz: 56a30016b7f290693c89d8f8e2fd4e3d8425962a2dcb0fb75c96bd6b2fc8b85b890373a4ebd160e7cf2896e494697a563dd882f11f7527da9c29234d41bd2b17
6
+ metadata.gz: efd8e608dfeafc5d7e7fcd06274b0b8ed0c640744ab9d8113597bef916f31666cbf518b1dcd6869d7af42fbcbaf15a6a4cf8100b97fcbf52f5ba790e495e26c0
7
+ data.tar.gz: dcc504641e1c22b24a05c76534e2f8ba7a7fd5ff1b5f891eb467d23876c60900ef235d2dd4ba49af4352b23ffd1cd246c720aff79668244b6a10cec3aab8ed6f
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source "https://rubygems.org"
3
3
 
4
4
  gemspec
5
5
 
6
+ gem "benchmark-ips"
7
+
6
8
  group :test do
7
9
  gem "coveralls"
8
10
  gem "json"
@@ -83,14 +83,17 @@ module SecureHeaders
83
83
  # can lead to modifying parent objects.
84
84
  def deep_copy(config)
85
85
  return unless config
86
- config.each_with_object({}) do |(key, value), hash|
87
- hash[key] =
88
- if value.is_a?(Array)
86
+ result = {}
87
+ config.each_pair do |key, value|
88
+ result[key] =
89
+ case value
90
+ when Array
89
91
  value.dup
90
92
  else
91
93
  value
92
94
  end
93
95
  end
96
+ result
94
97
  end
95
98
 
96
99
  # Private: Returns the internal default configuration. This should only
@@ -20,9 +20,9 @@ module SecureHeaders
20
20
  config
21
21
  end
22
22
 
23
- @preserve_schemes = @config.preserve_schemes
24
- @script_nonce = @config.script_nonce
25
- @style_nonce = @config.style_nonce
23
+ @preserve_schemes = @config[:preserve_schemes]
24
+ @script_nonce = @config[:script_nonce]
25
+ @style_nonce = @config[:style_nonce]
26
26
  end
27
27
 
28
28
  ##
@@ -1,65 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
  module SecureHeaders
3
3
  module DynamicConfig
4
- def self.included(base)
5
- base.send(:attr_reader, *base.attrs)
6
- base.attrs.each do |attr|
7
- base.send(:define_method, "#{attr}=") do |value|
8
- if self.class.attrs.include?(attr)
9
- write_attribute(attr, value)
10
- else
11
- raise ContentSecurityPolicyConfigError, "Unknown config directive: #{attr}=#{value}"
12
- end
13
- end
14
- end
15
- end
16
-
17
4
  def initialize(hash)
18
- @base_uri = nil
19
- @child_src = nil
20
- @connect_src = nil
21
- @default_src = nil
22
- @font_src = nil
23
- @form_action = nil
24
- @frame_ancestors = nil
25
- @frame_src = nil
26
- @img_src = nil
27
- @manifest_src = nil
28
- @media_src = nil
29
- @navigate_to = nil
30
- @object_src = nil
31
- @plugin_types = nil
32
- @prefetch_src = nil
33
- @preserve_schemes = nil
34
- @report_only = nil
35
- @report_uri = nil
36
- @require_sri_for = nil
37
- @require_trusted_types_for = nil
38
- @sandbox = nil
39
- @script_nonce = nil
40
- @script_src = nil
41
- @script_src_elem = nil
42
- @script_src_attr = nil
43
- @style_nonce = nil
44
- @style_src = nil
45
- @style_src_elem = nil
46
- @style_src_attr = nil
47
- @trusted_types = nil
48
- @worker_src = nil
49
- @upgrade_insecure_requests = nil
50
- @disable_nonce_backwards_compatibility = nil
5
+ @config = {}
51
6
 
52
7
  from_hash(hash)
53
8
  end
54
9
 
10
+ def initialize_copy(hash)
11
+ @config = hash.to_h
12
+ end
13
+
55
14
  def update_directive(directive, value)
56
- self.send("#{directive}=", value)
15
+ @config[directive] = value
57
16
  end
58
17
 
59
18
  def directive_value(directive)
60
- if self.class.attrs.include?(directive)
61
- self.send(directive)
62
- end
19
+ # No need to check attrs, as we only assign valid keys
20
+ @config[directive]
63
21
  end
64
22
 
65
23
  def merge(new_hash)
@@ -77,10 +35,7 @@ module SecureHeaders
77
35
  end
78
36
 
79
37
  def to_h
80
- self.class.attrs.each_with_object({}) do |key, hash|
81
- value = self.send(key)
82
- hash[key] = value unless value.nil?
83
- end
38
+ @config.dup
84
39
  end
85
40
 
86
41
  def dup
@@ -113,8 +68,11 @@ module SecureHeaders
113
68
 
114
69
  def write_attribute(attr, value)
115
70
  value = value.dup if PolicyManagement::DIRECTIVE_VALUE_TYPES[attr] == :source_list
116
- attr_variable = "@#{attr}"
117
- self.instance_variable_set(attr_variable, value)
71
+ if value.nil?
72
+ @config.delete(attr)
73
+ else
74
+ @config[attr] = value
75
+ end
118
76
  end
119
77
  end
120
78
 
@@ -122,7 +80,7 @@ module SecureHeaders
122
80
  class ContentSecurityPolicyConfig
123
81
  HEADER_NAME = "Content-Security-Policy".freeze
124
82
 
125
- ATTRS = PolicyManagement::ALL_DIRECTIVES + PolicyManagement::META_CONFIGS + PolicyManagement::NONCES
83
+ ATTRS = Set.new(PolicyManagement::ALL_DIRECTIVES + PolicyManagement::META_CONFIGS + PolicyManagement::NONCES)
126
84
  def self.attrs
127
85
  ATTRS
128
86
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecureHeaders
4
- VERSION = "6.6.0"
4
+ VERSION = "6.7.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secure_headers
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.6.0
4
+ version: 6.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Matatall