Skip to content

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
README.md Outdated
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

5 participants