Skip to content

New API Implementation - #191

Merged
oreoshake merged 24 commits into
3.xfrom
env-rack-config
Dec 11, 2015
Merged

New API Implementation#191
oreoshake merged 24 commits into
3.xfrom
env-rack-config

Conversation

@oreoshake

Copy link
Copy Markdown
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

classApplicationController < ActionController::BaseSecureHeaders::Configuration.defaultdo |config|
config.csp={default_src: %w('self'),script_src: %w(example.org)}end# override default configurationSecureHeaders::Configuration.override(:script_from_otherdomain_com)do |config|
config.csp[:script_src] << "otherdomain.com"end# overrides the :script_from_otherdomain_com configurationSecureHeaders::Configuration.override(:another_config,:script_from_otherdomain_com)do |config|
config.csp[:script_src] << "evenanotherdomain.com"endendclassMyController < ApplicationControllerdefindex# Produces default-src 'self'; script-src example.org otherdomain.orguse_secure_headers_override(:script_from_otherdomain_com)enddefshow# Produces default-src 'self'; script-src example.org otherdomain.org evenanotherdomain.comuse_secure_headers_override(:another_config)endend

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
@oreoshakeoreoshake mentioned this pull request Nov 5, 2015
9 tasks
Comment threadREADME.md Outdated

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.xDec 11, 2015
@oreoshake
oreoshake deleted the env-rack-config branch December 11, 2015 00:41
Sign up for freeto 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

@oreoshake@stve@reedloden@kevgo