@@ -24,7 +24,7 @@ module SecureHeaders
2424
2525 describe "#value" do
2626 it "discards 'none' values if any other source expressions are present" do
27- csp = ContentSecurityPolicy . new ( default_opts . merge ( frame_src : %w( 'self' 'none' ) ) )
27+ csp = ContentSecurityPolicy . new ( default_opts . merge ( child_src : %w( 'self' 'none' ) ) )
2828 expect ( csp . value ) . not_to include ( "'none'" )
2929 end
3030
@@ -86,42 +86,68 @@ module SecureHeaders
8686 expect ( csp . value ) . to eq ( "default-src example.org" )
8787 end
8888
89+ it "emits a warning when using frame-src" do
90+ expect ( Kernel ) . to receive ( :warn ) . with ( /:frame_src is deprecated, use :child_src instead./ )
91+ ContentSecurityPolicy . new ( default_src : %w( 'self' ) , frame_src : %w( 'self' ) ) . value
92+ end
93+
94+ it "emits a warning when child-src and frame-src are supplied but are not equal" do
95+ expect ( Kernel ) . to receive ( :warn ) . with ( /both :child_src and :frame_src supplied and do not match./ )
96+ ContentSecurityPolicy . new ( default_src : %w( 'self' ) , child_src : %w( child-src.com ) , frame_src : %w( frame-src,com ) ) . value
97+ end
98+
99+ it "will still set inconsistent child/frame-src values to be less surprising" do
100+ expect ( Kernel ) . to receive ( :warn ) . at_least ( :once )
101+ firefox = ContentSecurityPolicy . new ( { default_src : %w( 'self' ) , child_src : %w( child-src.com ) , frame_src : %w( frame-src,com ) } , USER_AGENTS [ :firefox ] ) . value
102+ firefox_transitional = ContentSecurityPolicy . new ( { default_src : %w( 'self' ) , child_src : %w( child-src.com ) , frame_src : %w( frame-src,com ) } , USER_AGENTS [ :firefox46 ] ) . value
103+ expect ( firefox ) . not_to eq ( firefox_transitional )
104+ expect ( firefox ) . to match ( /frame-src/ )
105+ expect ( firefox ) . not_to match ( /child-src/ )
106+ expect ( firefox_transitional ) . to match ( /child-src/ )
107+ expect ( firefox_transitional ) . not_to match ( /frame-src/ )
108+ end
109+
89110 context "browser sniffing" do
90111 let ( :complex_opts ) do
91- ContentSecurityPolicy ::ALL_DIRECTIVES . each_with_object ( { } ) do |directive , hash |
92- hash [ directive ] = %w( 'self' )
112+ ( ContentSecurityPolicy ::ALL_DIRECTIVES - [ :frame_src ] ) . each_with_object ( { } ) do |directive , hash |
113+ hash [ directive ] = [ " #{ directive . to_s . gsub ( "_" , "-" ) } .com" ]
93114 end . merge ( {
94115 block_all_mixed_content : true ,
95116 upgrade_insecure_requests : true ,
96117 reflected_xss : "block" ,
97- script_src : %w( 'self' ) ,
118+ script_src : %w( script-src.com ) ,
98119 script_nonce : 123456
99120 } )
100121 end
101122
102123 it "does not filter any directives for Chrome" do
103124 policy = ContentSecurityPolicy . new ( complex_opts , USER_AGENTS [ :chrome ] )
104- expect ( policy . value ) . to eq ( "default-src 'self' ; base-uri 'self' ; block-all-mixed-content; child-src 'self' ; connect-src 'self' ; font-src 'self' ; form-action 'self' ; frame-ancestors 'self'; frame-src 'self' ; img-src 'self' ; media-src 'self' ; object-src 'self' ; plugin-types 'self' ; sandbox 'self' ; script-src 'self' 'nonce-123456'; style-src 'self' ; upgrade-insecure-requests; report-uri 'self' " )
125+ expect ( policy . value ) . to eq ( "default-src default-src.com ; base-uri base-uri.com ; block-all-mixed-content; 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 ; upgrade-insecure-requests; report-uri report-uri.com " )
105126 end
106127
107128 it "does not filter any directives for Opera" do
108129 policy = ContentSecurityPolicy . new ( complex_opts , USER_AGENTS [ :opera ] )
109- expect ( policy . value ) . to eq ( "default-src 'self' ; base-uri 'self' ; block-all-mixed-content; child-src 'self' ; connect-src 'self' ; font-src 'self' ; form-action 'self' ; frame-ancestors 'self'; frame-src 'self' ; img-src 'self' ; media-src 'self' ; object-src 'self' ; plugin-types 'self' ; sandbox 'self' ; script-src 'self' 'nonce-123456'; style-src 'self' ; upgrade-insecure-requests; report-uri 'self' " )
130+ expect ( policy . value ) . to eq ( "default-src default-src.com ; base-uri base-uri.com ; block-all-mixed-content; 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 ; upgrade-insecure-requests; report-uri report-uri.com " )
110131 end
111132
112133 it "filters blocked-all-mixed-content, child-src, and plugin-types for firefox" do
113134 policy = ContentSecurityPolicy . new ( complex_opts , USER_AGENTS [ :firefox ] )
114- expect ( policy . value ) . to eq ( "default-src 'self'; base-uri 'self'; connect-src 'self'; font-src 'self'; form-action 'self'; frame-ancestors 'self'; frame-src 'self'; img-src 'self'; media-src 'self'; object-src 'self'; sandbox 'self'; script-src 'self' 'nonce-123456'; style-src 'self'; upgrade-insecure-requests; report-uri 'self'" )
135+ expect ( policy . value ) . to eq ( "default-src default-src.com; base-uri base-uri.com; connect-src connect-src.com; font-src font-src.com; form-action form-action.com; frame-ancestors frame-ancestors.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 'nonce-123456'; style-src style-src.com; upgrade-insecure-requests; report-uri report-uri.com" )
136+ end
137+
138+ it "filters blocked-all-mixed-content, frame-src, and plugin-types for firefox 46 and higher" do
139+ policy = ContentSecurityPolicy . new ( complex_opts , USER_AGENTS [ :firefox46 ] )
140+ 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; sandbox sandbox.com; script-src script-src.com 'nonce-123456'; style-src style-src.com; upgrade-insecure-requests; report-uri report-uri.com" )
115141 end
116142
117- it "adds 'unsafe-inline', filters base-uri, blocked-all-mixed-content, upgrade-insecure-requests, child-src, form-action, frame-ancestors, nonce sources, hash sources, and plugin-types for Edge" do
143+ it "child-src value is copied to frame-src, adds 'unsafe-inline', filters base-uri, blocked-all-mixed-content, upgrade-insecure-requests, child-src, form-action, frame-ancestors, nonce sources, hash sources, and plugin-types for Edge" do
118144 policy = ContentSecurityPolicy . new ( complex_opts , USER_AGENTS [ :edge ] )
119- expect ( policy . value ) . to eq ( "default-src 'self' ; connect-src 'self' ; font-src 'self' ; frame-src 'self' ; img-src 'self' ; media-src 'self' ; object-src 'self' ; sandbox 'self' ; script-src 'self' 'unsafe-inline'; style-src 'self' ; report-uri 'self' " )
145+ 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 " )
120146 end
121147
122- it "adds 'unsafe-inline', filters base-uri, blocked-all-mixed-content, upgrade-insecure-requests, child-src, form-action, frame-ancestors, nonce sources, hash sources, and plugin-types for safari" do
148+ it "child-src value is copied to frame-src, adds 'unsafe-inline', filters base-uri, blocked-all-mixed-content, upgrade-insecure-requests, child-src, form-action, frame-ancestors, nonce sources, hash sources, and plugin-types for safari" do
123149 policy = ContentSecurityPolicy . new ( complex_opts , USER_AGENTS [ :safari6 ] )
124- expect ( policy . value ) . to eq ( "default-src 'self' ; connect-src 'self' ; font-src 'self' ; frame-src 'self' ; img-src 'self' ; media-src 'self' ; object-src 'self' ; sandbox 'self' ; script-src 'self' 'unsafe-inline'; style-src 'self' ; report-uri 'self' " )
150+ 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 " )
125151 end
126152 end
127153 end
0 commit comments