File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -224,8 +224,9 @@ def combine_policies(original, additions)
224224 end
225225
226226 def ua_to_variation ( user_agent )
227- if family = user_agent . browser && VARIATIONS . key? ( family )
228- VARIATIONS [ family ]
227+ family = user_agent . browser
228+ if family && VARIATIONS . key? ( family )
229+ family
229230 else
230231 OTHER
231232 end
Original file line number Diff line number Diff line change @@ -61,6 +61,25 @@ module SecureHeaders
6161 expect ( hash [ XFrameOptions ::HEADER_NAME ] ) . to eq ( XFrameOptions ::SAMEORIGIN )
6262 end
6363
64+ it "produces a UA-specific CSP when overriding (and busting the cache)" do
65+ config = Configuration . default do |config |
66+ config . csp = {
67+ default_src : %w( 'self' ) ,
68+ child_src : %w( 'self' ) , #unsupported by firefox
69+ frame_src : %w( 'self' )
70+ }
71+ end
72+ firefox_request = Rack ::Request . new ( request . env . merge ( "HTTP_USER_AGENT" => USER_AGENTS [ :firefox ] ) )
73+
74+ # append an unsupported directive
75+ SecureHeaders . override_content_security_policy_directives ( firefox_request , plugin_types : %w( flash ) )
76+ # append a supported directive
77+ SecureHeaders . override_content_security_policy_directives ( firefox_request , script_src : %w( 'self' ) )
78+
79+ hash = SecureHeaders . header_hash_for ( firefox_request )
80+ expect ( hash [ CSP ::HEADER_NAME ] ) . to eq ( "default-src 'self'; frame-src 'self'; script-src 'self'" )
81+ end
82+
6483 it "produces a hash of headers with default config" do
6584 Configuration . default
6685 hash = SecureHeaders . header_hash_for ( request )
You can’t perform that action at this time.
0 commit comments