Skip to content
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

Set two csp headers (enforced and report only) #256

Closed
davidhan527 opened this issue May 10, 2016 · 4 comments
Closed

Set two csp headers (enforced and report only) #256

davidhan527 opened this issue May 10, 2016 · 4 comments
Labels

Comments

@davidhan527
Copy link
Contributor

Is there a way using secure headers, to set both an enforced and report only header? A lot of people might want to do this in order to experiment with a different policy configuration and see what violation may occur before actually enforcing it.

@oreoshake
Copy link
Contributor

oreoshake commented May 10, 2016

secure_headers provides classes for generating headers based on configs. However, there isn't a way to do this with just config.

header = ContentSecurityPolicy.new(config, user_agent)
response.headers[header.name] = header.value

I think doing this in config alone would be great addition.

@oreoshake
Copy link
Contributor

I think adding something like this would work well:

SecureHeaders::Configuration.default do |config|
  config.csp = { default_src: 'self' ... }  
  config.csp_report_only = { default_src: 'none' ... }  
end

@oreoshake
Copy link
Contributor

I was just thinking about this. Specifically, should there be a flag to indicate which policy the override is meant for (that defaults to both)?

SecureHeaders::Configuration.default do |config|
   config.csp = {
     default_src: ['none'],
     script_src: %w(example.com anotherexample.com)
   }

   config.csp_report_only = config.csp.merge { 
     script_src: %w(example.com) # more restrictive, fewer hosts
   }
end

Somewhere in a controller...

append_content_security_policy_directives(:script_src, ['thirdparty.com'], :enforced)
override_content_security_policy_directives(:script_src, ['none'], :report_only)

Would result in

Content-Security-Policy: default-src 'none'; script_src example.com anotherexample.com thirdparty.com
Content-Security-Policy-Report-Only: default-src 'none'; script_src 'none'

@oreoshake
Copy link
Contributor

fyi there's a PR for this #281

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants