Add config to use Rails for secure headers options (LG-5771)#5952
Add config to use Rails for secure headers options (LG-5771)#5952zachmargolis merged 4 commits intomainfrom
Conversation
aduth
left a comment
There was a problem hiding this comment.
Re: Defaults:
- The default for
X-XSS-Protection("0") doesn't match what we had. Do we want it to? - The default for
X-Download-Optionswill be removed in Rails 7.1. Do we care to keep it set?
spec/requests/headers_spec.rb
Outdated
| it 'includes Strict-Transport-Security (HSTS)' do | ||
| get root_path | ||
|
|
||
| pending 'seems to not get set in plain http tests' |
There was a problem hiding this comment.
Can we force it to request as https: ? Edit: Or is this also related to your original comment about secure_headers gem clobbering?
There was a problem hiding this comment.
The clobbering was mostly related to the action_dispatch.default_headers this was me being lazy... but with some Googling I found that this works: 9e1077b
| @@ -1,5 +1,15 @@ | |||
| require 'feature_management' | |||
|
|
|||
| if IdentityConfig.store.rails_csp_tooling_enabled | |||
There was a problem hiding this comment.
To keep inline with the other calls in this file it should be if FeatureManagement.rails_csp_tooling_enabled?
which calls this method.
There was a problem hiding this comment.
Good point, will update
My original process was trying to create the minimal changes that preserve the behavior we have now. That approach meant that if we upgraded to Rails 7, or 7.1, the default headers would change and the specs would break. Based on this comment, and to hopefully head off some future confusion, I added b621825 to keep what we now have as our default behavior in the future |
The bulk of this PR is setting up regression specs so we can remove SecureHeaders gem confidently
The configs:
identity-idp/config/initializers/secure_headers.rb
Lines 4 to 9 in 27742c5
Looks like most of our desired headers match with the defaults for Rails: https://edgeguides.rubyonrails.org/configuring.html#config-action-dispatch-default-headers
The way SecureHeaders is implemented, it stomps on the
default_headersconfig very late in the game: https://github.com/github/secure_headers/blob/ce2ad139646f9775061159fe5c4707638fbe45c1/lib/secure_headers/railtie.rb#L21-L31so the only way to test this code was to comment out/remove secure_headers gem entirely and make sure the specs worked as expected
This does mean that this test should be good regression for when we do remove the gem entirely