Skip to content

Commit 6b49c0f

Browse files
committed
Merge branch 'secure-headers-x' of https://github.com/ptoomey3/secureheaders into secure-headers-x
2 parents b82b56d + 15581b4 commit 6b49c0f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

docs/upgrading-to-6-0.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
The original implementation of name overrides worked by making a copy of the default policy, applying the overrides, and storing the result for later use. But, this lead to unexpected results if named overrides were combined with a dynamic policy change. If a change was made to the default configuration during a request, followed by a named override, the dynamic changes would be lost. To keep things consistent named overrides have been rewritten to work the same as named appends in that they always operate on the configuration for the current request. As an example:
44

55
```ruby
6-
# specific opt outs
7-
Configuration.default do |config|
8-
config.x_frame_options = OPT_OUT
6+
class ApplicationController < ActionController::Base
7+
Configuration.default do |config|
8+
config.x_frame_options = OPT_OUT
9+
end
10+
11+
SecureHeaders::Configuration.override(:dynamic_override) do |config|
12+
config.x_content_type_options = "nosniff"
13+
end
914
end
1015

11-
# Dynamically update the default config for this request
12-
SecureHeaders.override_x_frame_options(request, "DENY")
16+
class FooController < ApplicationController
17+
def bar
18+
# Dynamically update the default config for this request
19+
override_x_frame_options("DENY")
20+
append_content_security_policy_directives(frame_src: "3rdpartyprovider.com")
1321

14-
SecureHeaders::Configuration.override(:dynamic_override) do |config|
15-
config.x_content_type_options = "nosniff"
22+
# Override everything, discard modifications above
23+
use_secure_headers_override(:dynamic_override)
24+
end
1625
end
17-
18-
SecureHeaders.use_secure_headers_override(request, :dynamic_override)
1926
```
2027

2128
Prior to 6.0.0, the response would NOT include a `X-Frame-Options` header since the named override would be a copy of the default configuration, but with `X-Content-Type-Options` set to `nosniff`. As of 6.0.0, the above code results in both `X-Frame-Options` set to `DENY` AND `X-Content-Type-Options` set to `nosniff`.

0 commit comments

Comments
 (0)