File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ def opt_out?
4747 SECURE_HEADERS_CONFIG = "secure_headers_request_config" . freeze
4848 NONCE_KEY = "secure_headers_content_security_policy_nonce" . freeze
4949 HTTPS = "https" . freeze
50+ CSP = ContentSecurityPolicy
5051
5152 ALL_HEADER_CLASSES = [
5253 ContentSecurityPolicyConfig ,
Original file line number Diff line number Diff line change @@ -224,8 +224,7 @@ def supported_directives
224224 end
225225
226226 def nonces_supported?
227- @nonces_supported ||= MODERN_BROWSERS . include? ( @parsed_ua . browser ) ||
228- @parsed_ua . browser == "Safari" && @parsed_ua . version >= VERSION_10
227+ @nonces_supported ||= self . class . nonces_supported? ( @parsed_ua )
229228 end
230229
231230 def symbol_to_hyphen_case ( sym )
Original file line number Diff line number Diff line change @@ -211,6 +211,15 @@ def validate_config!(config)
211211 end
212212 end
213213
214+ # Public: check if a user agent supports CSP nonces
215+ #
216+ # user_agent - a String or a UserAgent object
217+ def nonces_supported? ( user_agent )
218+ user_agent = UserAgent . parse ( user_agent ) if user_agent . is_a? ( String )
219+ MODERN_BROWSERS . include? ( user_agent . browser ) ||
220+ user_agent . browser == "Safari" && user_agent . version >= CSP ::VERSION_10
221+ end
222+
214223 # Public: combine the values from two different configs.
215224 #
216225 # original - the main config
You can’t perform that action at this time.
0 commit comments