Skip to content

New API Implementation #191

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

Merged
merged 24 commits into from
Dec 11, 2015
Merged

New API Implementation #191

merged 24 commits into from
Dec 11, 2015

Conversation

oreoshake
Copy link
Contributor

Followup to #181. As with the last PR, it's probably better to ignore the diff and look at the code directly.

The biggest change in this PR is the added support for "named overrides" - additional configuration objects that can be referenced by name. The header values are all precomputed so named overrides save the overhead of building a policy per request.

(from the readme

class ApplicationController < ActionController::Base
  SecureHeaders::Configuration.default do |config|
    config.csp = {
      default_src: %w('self'),
      script_src: %w(example.org)
    }
  end

  # override default configuration
  SecureHeaders::Configuration.override(:script_from_otherdomain_com) do |config|
    config.csp[:script_src] << "otherdomain.com"
  end

  # overrides the :script_from_otherdomain_com configuration
  SecureHeaders::Configuration.override(:another_config, :script_from_otherdomain_com) do |config|
    config.csp[:script_src] << "evenanotherdomain.com"
  end
end

class MyController < ApplicationController
  def index
    # Produces default-src 'self'; script-src example.org otherdomain.org
    use_secure_headers_override(:script_from_otherdomain_com)
  end

  def show
    # Produces default-src 'self'; script-src example.org otherdomain.org evenanotherdomain.com
    use_secure_headers_override(:another_config)
  end
end

fix regression with mutation of global state
Thanks to @igrep for pointing this out.

Fixes #187
Configure a global default and named overrides
Use helper methods to set/modify configurations at runtime
Set the headers in middleware based on the configuration saved to request.env

Configuration changes:
All headers require string values except for CSP and HPKP
CSP directives must be arrays of strings, no more support for space-delimited strings or procs
@oreoshake oreoshake mentioned this pull request Nov 5, 2015
9 tasks
}
config.hpkp = {
:max_age => 60.days.to_i,
:include_subdomains => true,
:report_uri => '//example.com/uri-directive',
:report_uri => "https//example.com/uri-directive",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a : here

@oreoshake
Copy link
Contributor Author

This code is now running on github.com. I'll let it sit for a few days and release a 3.0 gem. I'll add an "upgrading to 3.0 wiki" entry in the meantime since it is very much a breaking change.

oreoshake added a commit that referenced this pull request Dec 11, 2015
@oreoshake oreoshake merged commit 1918ce2 into 3.x Dec 11, 2015
@oreoshake oreoshake deleted the env-rack-config branch December 11, 2015 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants