-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Per instance hook #146
Comments
That's a great idea! It's been asked for before. BTW all csp config values accept procs which can work for simple cases. I do like this approach, but This could also be extended to the rest of the config so maybe something like wdyt? |
Cool. I just realized that what I'm doing doesn't need something on a per action basis. It needs it on a per instance basis. I've updated the title of the issue to reflect this. Sorry. I agree that The 2 key things this helps with are:
|
#override
def secure_headers_options_for
options = super
if current_user.is_totally_not_a_hacker?
options[:csp][:script_src] = "*"
options[:hsts][:include_subdomains] = false
end
options
end
def secure_headers_csp_options_for
{ script_src: 'self' } if current_user.is_totally_not_a_hacker?
end |
I may be missing something but I don't think that's how ::SecureHeaders::Configuration.configure do |config|
config.csp = {
:default_src => "https: self",
:frame_src => "https: http:.twimg.com http://itunes.apple.com"
}
config.hpkp = {
:max_age => 60.days.to_i,
:include_subdomains => true
}
end opts = options_for(:csp, nil)
# {
# :default_src => "https: self",
# :frame_src => "https: http:.twimg.com http://itunes.apple.com"
# } |
Oh I'm sorry you're right. And therefore my earlier concern is off-base |
Howdy,
Great gem, thanks! I was wondering if there's any way to modify the headers on a per instance basis? For example using the CSP preferences for the current user.
I had a quick peek into the source code and couldn't find a hook point that would achieve this. However with a small modification I think this could be achieved. I was thinking that instead of calling
self.class.options_for
it could call an instance methodself.options_for
which would do the same thing. That would then allow you to usesuper
and you can modify the returned options hash. Something along these lines.The text was updated successfully, but these errors were encountered: