Skip to content

Commit

Permalink
Merge pull request #319 from necolt/safari10-csp2
Browse files Browse the repository at this point in the history
Added CSP2 support for Safari 10+
  • Loading branch information
oreoshake committed Mar 3, 2017
2 parents 68ea150 + 86b270b commit ad5ac24
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/secure_headers/headers/content_security_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def supported_directives
@supported_directives ||= if VARIATIONS[@parsed_ua.browser]
if @parsed_ua.browser == "Firefox" && ((@parsed_ua.version || FALLBACK_VERSION) >= VERSION_46)
VARIATIONS["FirefoxTransitional"]
elsif @parsed_ua.browser == "Safari" && ((@parsed_ua.version || FALLBACK_VERSION) >= VERSION_10)
VARIATIONS["SafariTransitional"]
else
VARIATIONS[@parsed_ua.browser]
end
Expand Down
2 changes: 2 additions & 0 deletions lib/secure_headers/headers/policy_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def self.included(base)

EDGE_DIRECTIVES = DIRECTIVES_1_0
SAFARI_DIRECTIVES = DIRECTIVES_1_0
SAFARI_10_DIRECTIVES = DIRECTIVES_2_0

FIREFOX_UNSUPPORTED_DIRECTIVES = [
BLOCK_ALL_MIXED_CONTENT,
Expand Down Expand Up @@ -133,6 +134,7 @@ def self.included(base)
"Firefox" => FIREFOX_DIRECTIVES,
"FirefoxTransitional" => FIREFOX_46_DIRECTIVES,
"Safari" => SAFARI_DIRECTIVES,
"SafariTransitional" => SAFARI_10_DIRECTIVES,
"Edge" => EDGE_DIRECTIVES,
"Other" => CHROME_DIRECTIVES
}.freeze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ module SecureHeaders
expect(policy.value).to eq("default-src default-src.com; connect-src connect-src.com; font-src font-src.com; frame-src child-src.com; img-src img-src.com; media-src media-src.com; object-src object-src.com; sandbox sandbox.com; script-src script-src.com 'unsafe-inline'; style-src style-src.com; report-uri report-uri.com")
end

it "adds 'unsafe-inline', filters blocked-all-mixed-content, upgrade-insecure-requests, nonce sources, and hash sources for safari 10 and higher" do
policy = ContentSecurityPolicy.new(complex_opts, USER_AGENTS[:safari10])
expect(policy.value).to eq("default-src default-src.com; base-uri base-uri.com; child-src child-src.com; connect-src connect-src.com; font-src font-src.com; form-action form-action.com; frame-ancestors frame-ancestors.com; img-src img-src.com; media-src media-src.com; object-src object-src.com; plugin-types plugin-types.com; sandbox sandbox.com; script-src script-src.com 'nonce-123456'; style-src style-src.com; report-uri report-uri.com")
end

it "falls back to standard Firefox defaults when the useragent version is not present" do
ua = USER_AGENTS[:firefox].dup
allow(ua).to receive(:version).and_return(nil)
Expand Down

0 comments on commit ad5ac24

Please sign in to comment.