File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,13 @@ def dup
121121 copy . csp = self . class . send ( :deep_copy_if_hash , @csp )
122122 copy . dynamic_csp = self . class . send ( :deep_copy_if_hash , @dynamic_csp )
123123 copy . cached_headers = self . class . send ( :deep_copy_if_hash , @cached_headers )
124+ copy . x_content_type_options = @x_content_type_options
125+ copy . hsts = @hsts
126+ copy . x_frame_options = @x_frame_options
127+ copy . x_xss_protection = @x_xss_protection
128+ copy . x_download_options = @x_download_options
129+ copy . x_permitted_cross_domain_policies = @x_permitted_cross_domain_policies
130+ copy . hpkp = @hpkp
124131 copy
125132 end
126133
@@ -133,6 +140,7 @@ def opt_out(header)
133140 end
134141
135142 def update_x_frame_options ( value )
143+ @x_frame_options = value
136144 self . cached_headers [ XFrameOptions ::CONFIG_KEY ] = XFrameOptions . make_header ( value )
137145 end
138146
Original file line number Diff line number Diff line change @@ -41,6 +41,14 @@ module SecureHeaders
4141 end
4242 end
4343
44+ it "regenerates cached headers when building an override" do
45+ Configuration . override ( :test_override ) do |config |
46+ config . x_content_type_options = OPT_OUT
47+ end
48+
49+ expect ( Configuration . get . cached_headers ) . to_not eq ( Configuration . get ( :test_override ) . cached_headers )
50+ end
51+
4452 it "stores an override of the global config" do
4553 Configuration . override ( :test_override ) do |config |
4654 config . x_frame_options = "DENY"
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ module SecureHeaders
2121 end
2222
2323 describe "#header_hash_for" do
24- it "allows you to opt out of individual headers" do
24+ it "allows you to opt out of individual headers via API " do
2525 Configuration . default
2626 SecureHeaders . opt_out_of_header ( request , CSP ::CONFIG_KEY )
2727 SecureHeaders . opt_out_of_header ( request , XContentTypeOptions ::CONFIG_KEY )
@@ -31,6 +31,23 @@ module SecureHeaders
3131 expect ( hash [ 'X-Content-Type-Options' ] ) . to be_nil
3232 end
3333
34+ it "Carries options over when using overrides" do
35+ Configuration . default do |config |
36+ config . x_download_options = OPT_OUT
37+ config . x_permitted_cross_domain_policies = OPT_OUT
38+ end
39+
40+ Configuration . override ( :api ) do |config |
41+ config . x_frame_options = OPT_OUT
42+ end
43+
44+ SecureHeaders . use_secure_headers_override ( request , :api )
45+ hash = SecureHeaders . header_hash_for ( request )
46+ expect ( hash [ 'X-Download-Options' ] ) . to be_nil
47+ expect ( hash [ 'X-Permitted-Cross-Domain-Policies' ] ) . to be_nil
48+ expect ( hash [ 'X-Frame-Options' ] ) . to be_nil
49+ end
50+
3451 it "allows you to opt out entirely" do
3552 Configuration . default
3653 SecureHeaders . opt_out_of_all_protection ( request )
You can’t perform that action at this time.
0 commit comments