From 5f77446dbacd2be02018a1847807670a62df5e22 Mon Sep 17 00:00:00 2001 From: Neil Matatall Date: Mon, 18 Apr 2016 11:14:58 -1000 Subject: [PATCH] changelog/version bump for 3.2.0 --- CHANGELOG.md | 117 +++++++++++++++++++++++++++++++++++++++++ secure_headers.gemspec | 2 +- 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b050d41..7415653c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,120 @@ +## 3.2.0 Cookie settings and CSP hash sources + +### Cookies + +SecureHeaders supports `Secure`, `HttpOnly` and [`SameSite`](https://tools.ietf.org/html/draft-west-first-party-cookies-07) cookies. These can be defined in the form of a boolean, or as a Hash for more refined configuration. + +__Note__: Regardless of the configuration specified, Secure cookies are only enabled for HTTPS requests. + +#### Boolean-based configuration + +Boolean-based configuration is intended to globally enable or disable a specific cookie attribute. + +```ruby +config.cookies = { + secure: true, # mark all cookies as Secure + httponly: false, # do not mark any cookies as HttpOnly +} +``` + +#### Hash-based configuration + +Hash-based configuration allows for fine-grained control. + +```ruby +config.cookies = { + secure: { except: ['_guest'] }, # mark all but the `_guest` cookie as Secure + httponly: { only: ['_rails_session'] }, # only mark the `_rails_session` cookie as HttpOnly +} +``` + +#### SameSite cookie configuration + +SameSite cookies permit either `Strict` or `Lax` enforcement mode options. + +```ruby +config.cookies = { + samesite: { + strict: true # mark all cookies as SameSite=Strict + } +} +``` + +`Strict` and `Lax` enforcement modes can also be specified using a Hash. + +```ruby +config.cookies = { + samesite: { + strict: { only: ['_rails_session'] }, + lax: { only: ['_guest'] } + } +} +``` + +#### Hash + +`script`/`style-src` hashes can be used to whitelist inline content that is static. This has the benefit of allowing inline content without opening up the possibility of dynamic javascript like you would with a `nonce`. + +You can add hash sources directly to your policy : + +```ruby +::SecureHeaders::Configuration.default do |config| + config.csp = { + default_src: %w('self') + + # this is a made up value but browsers will show the expected hash in the console. + script_src: %w(sha256-123456) + } + end + ``` + + You can also use the automated inline script detection/collection/computation of hash source values in your app. + + ```bash + rake secure_headers:generate_hashes + ``` + + This will generate a file (`config/config/secure_headers_generated_hashes.yml` by default, you can override by setting `ENV["secure_headers_generated_hashes_file"]`) containing a mapping of file names with the array of hash values found on that page. When ActionView renders a given file, we check if there are any known hashes for that given file. If so, they are added as values to the header. + +```yaml +--- +scripts: + app/views/asdfs/index.html.erb: + - "'sha256-yktKiAsZWmc8WpOyhnmhQoDf9G2dAZvuBBC+V0LGQhg='" +styles: + app/views/asdfs/index.html.erb: + - "'sha256-SLp6LO3rrKDJwsG9uJUxZapb4Wp2Zhj6Bu3l+d9rnAY='" + - "'sha256-HSGHqlRoKmHAGTAJ2Rq0piXX4CnEbOl1ArNd6ejp2TE='" +``` + +##### Helpers + +**This will not compute dynamic hashes** by design. The output of both helpers will be a plain `script`/`style` tag without modification and the known hashes for a given file will be added to `script-src`/`style-src` when `hashed_javascript_tag` and `hashed_style_tag` are used. You can use `raise_error_on_unrecognized_hash = true` to be extra paranoid that you have precomputed hash values for all of your inline content. By default, this will raise an error in non-production environments. + +```erb +<%= hashed_style_tag do %> +body { + background-color: black; +} +<% end %> + +<%= hashed_style_tag do %> +body { + font-size: 30px; + font-color: green; +} +<% end %> + +<%= hashed_javascript_tag do %> +console.log(1) +<% end %> +``` + +``` +Content-Security-Policy: ... + script-src 'sha256-yktKiAsZWmc8WpOyhnmhQoDf9G2dAZvuBBC+V0LGQhg=' ... ; + style-src 'sha256-SLp6LO3rrKDJwsG9uJUxZapb4Wp2Zhj6Bu3l+d9rnAY=' 'sha256-HSGHqlRoKmHAGTAJ2Rq0piXX4CnEbOl1ArNd6ejp2TE=' ...; + ## 3.1.2 Bug fix for regression See https://github.com/twitter/secureheaders/pull/239 diff --git a/secure_headers.gemspec b/secure_headers.gemspec index af75980d..c1c16f3b 100644 --- a/secure_headers.gemspec +++ b/secure_headers.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |gem| gem.name = "secure_headers" - gem.version = "3.1.2" + gem.version = "3.2.0" gem.authors = ["Neil Matatall"] gem.email = ["neil.matatall@gmail.com"] gem.description = 'Security related headers all in one gem.'