secure_headers 6.6.0 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6919954e57f87c70a4fa42baa5285649bd7484ec6785894a2b461b6f52558f29
|
4
|
+
data.tar.gz: 710492a0e64a47f41f2b079e6d4799922aa05e51d017cacafcc20d77383815ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efd8e608dfeafc5d7e7fcd06274b0b8ed0c640744ab9d8113597bef916f31666cbf518b1dcd6869d7af42fbcbaf15a6a4cf8100b97fcbf52f5ba790e495e26c0
|
7
|
+
data.tar.gz: dcc504641e1c22b24a05c76534e2f8ba7a7fd5ff1b5f891eb467d23876c60900ef235d2dd4ba49af4352b23ffd1cd246c720aff79668244b6a10cec3aab8ed6f
|
data/Gemfile
CHANGED
@@ -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
|
-
|
87
|
-
|
88
|
-
|
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
|
24
|
-
@script_nonce = @config
|
25
|
-
@style_nonce = @config
|
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
|
-
@
|
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
|
-
|
15
|
+
@config[directive] = value
|
57
16
|
end
|
58
17
|
|
59
18
|
def directive_value(directive)
|
60
|
-
|
61
|
-
|
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
|
-
|
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
|
-
|
117
|
-
|
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
|