Skip to content

Commit 5f77446

Browse files
committed
changelog/version bump for 3.2.0
1 parent c618d70 commit 5f77446

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

CHANGELOG.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,120 @@
1+
## 3.2.0 Cookie settings and CSP hash sources
2+
3+
### Cookies
4+
5+
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.
6+
7+
__Note__: Regardless of the configuration specified, Secure cookies are only enabled for HTTPS requests.
8+
9+
#### Boolean-based configuration
10+
11+
Boolean-based configuration is intended to globally enable or disable a specific cookie attribute.
12+
13+
```ruby
14+
config.cookies = {
15+
secure: true, # mark all cookies as Secure
16+
httponly: false, # do not mark any cookies as HttpOnly
17+
}
18+
```
19+
20+
#### Hash-based configuration
21+
22+
Hash-based configuration allows for fine-grained control.
23+
24+
```ruby
25+
config.cookies = {
26+
secure: { except: ['_guest'] }, # mark all but the `_guest` cookie as Secure
27+
httponly: { only: ['_rails_session'] }, # only mark the `_rails_session` cookie as HttpOnly
28+
}
29+
```
30+
31+
#### SameSite cookie configuration
32+
33+
SameSite cookies permit either `Strict` or `Lax` enforcement mode options.
34+
35+
```ruby
36+
config.cookies = {
37+
samesite: {
38+
strict: true # mark all cookies as SameSite=Strict
39+
}
40+
}
41+
```
42+
43+
`Strict` and `Lax` enforcement modes can also be specified using a Hash.
44+
45+
```ruby
46+
config.cookies = {
47+
samesite: {
48+
strict: { only: ['_rails_session'] },
49+
lax: { only: ['_guest'] }
50+
}
51+
}
52+
```
53+
54+
#### Hash
55+
56+
`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`.
57+
58+
You can add hash sources directly to your policy :
59+
60+
```ruby
61+
::SecureHeaders::Configuration.default do |config|
62+
config.csp = {
63+
default_src: %w('self')
64+
65+
# this is a made up value but browsers will show the expected hash in the console.
66+
script_src: %w(sha256-123456)
67+
}
68+
end
69+
```
70+
71+
You can also use the automated inline script detection/collection/computation of hash source values in your app.
72+
73+
```bash
74+
rake secure_headers:generate_hashes
75+
```
76+
77+
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.
78+
79+
```yaml
80+
---
81+
scripts:
82+
app/views/asdfs/index.html.erb:
83+
- "'sha256-yktKiAsZWmc8WpOyhnmhQoDf9G2dAZvuBBC+V0LGQhg='"
84+
styles:
85+
app/views/asdfs/index.html.erb:
86+
- "'sha256-SLp6LO3rrKDJwsG9uJUxZapb4Wp2Zhj6Bu3l+d9rnAY='"
87+
- "'sha256-HSGHqlRoKmHAGTAJ2Rq0piXX4CnEbOl1ArNd6ejp2TE='"
88+
```
89+
90+
##### Helpers
91+
92+
**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.
93+
94+
```erb
95+
<%= hashed_style_tag do %>
96+
body {
97+
background-color: black;
98+
}
99+
<% end %>
100+
101+
<%= hashed_style_tag do %>
102+
body {
103+
font-size: 30px;
104+
font-color: green;
105+
}
106+
<% end %>
107+
108+
<%= hashed_javascript_tag do %>
109+
console.log(1)
110+
<% end %>
111+
```
112+
113+
```
114+
Content-Security-Policy: ...
115+
script-src 'sha256-yktKiAsZWmc8WpOyhnmhQoDf9G2dAZvuBBC+V0LGQhg=' ... ;
116+
style-src 'sha256-SLp6LO3rrKDJwsG9uJUxZapb4Wp2Zhj6Bu3l+d9rnAY=' 'sha256-HSGHqlRoKmHAGTAJ2Rq0piXX4CnEbOl1ArNd6ejp2TE=' ...;
117+
1118
## 3.1.2 Bug fix for regression
2119

3120
See https://github.com/twitter/secureheaders/pull/239

secure_headers.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- encoding: utf-8 -*-
22
Gem::Specification.new do |gem|
33
gem.name = "secure_headers"
4-
gem.version = "3.1.2"
4+
gem.version = "3.2.0"
55
gem.authors = ["Neil Matatall"]
66
gem.email = ["[email protected]"]
77
gem.description = 'Security related headers all in one gem.'

0 commit comments

Comments
 (0)