Skip to content

Commit

Permalink
make the nonce support helper method public
Browse files Browse the repository at this point in the history
  • Loading branch information
oreoshake committed Sep 29, 2016
1 parent 7801462 commit 680e7e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/secure_headers.rb
Expand Up @@ -47,6 +47,7 @@ def opt_out?
SECURE_HEADERS_CONFIG = "secure_headers_request_config".freeze
NONCE_KEY = "secure_headers_content_security_policy_nonce".freeze
HTTPS = "https".freeze
CSP = ContentSecurityPolicy

ALL_HEADER_CLASSES = [
ContentSecurityPolicyConfig,
Expand Down
3 changes: 1 addition & 2 deletions lib/secure_headers/headers/content_security_policy.rb
Expand Up @@ -224,8 +224,7 @@ def supported_directives
end

def nonces_supported?
@nonces_supported ||= MODERN_BROWSERS.include?(@parsed_ua.browser) ||
@parsed_ua.browser == "Safari" && @parsed_ua.version >= VERSION_10
@nonces_supported ||= self.class.nonces_supported?(@parsed_ua)
end

def symbol_to_hyphen_case(sym)
Expand Down
9 changes: 9 additions & 0 deletions lib/secure_headers/headers/policy_management.rb
Expand Up @@ -211,6 +211,15 @@ def validate_config!(config)
end
end

# Public: check if a user agent supports CSP nonces
#
# user_agent - a String or a UserAgent object
def nonces_supported?(user_agent)
user_agent = UserAgent.parse(user_agent) if user_agent.is_a?(String)
MODERN_BROWSERS.include?(user_agent.browser) ||
user_agent.browser == "Safari" && user_agent.version >= CSP::VERSION_10
end

# Public: combine the values from two different configs.
#
# original - the main config
Expand Down

0 comments on commit 680e7e9

Please sign in to comment.