secure_headers 3.0.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +41 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +20 -0
- data/.gitignore +0 -9
- data/.rspec +2 -0
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -1
- data/.travis.yml +17 -5
- data/CHANGELOG.md +287 -0
- data/CODE_OF_CONDUCT.md +46 -0
- data/CONTRIBUTING.md +41 -0
- data/Gemfile +13 -5
- data/Guardfile +1 -0
- data/LICENSE +4 -199
- data/README.md +85 -265
- data/Rakefile +22 -18
- data/docs/HPKP.md +17 -0
- data/docs/cookies.md +64 -0
- data/docs/hashes.md +64 -0
- data/docs/named_overrides_and_appends.md +107 -0
- data/docs/per_action_configuration.md +133 -0
- data/docs/sinatra.md +25 -0
- data/lib/secure_headers/configuration.rb +188 -59
- data/lib/secure_headers/hash_helper.rb +11 -0
- data/lib/secure_headers/headers/clear_site_data.rb +55 -0
- data/lib/secure_headers/headers/content_security_policy.rb +136 -325
- data/lib/secure_headers/headers/content_security_policy_config.rb +162 -0
- data/lib/secure_headers/headers/cookie.rb +144 -0
- data/lib/secure_headers/headers/expect_certificate_transparency.rb +70 -0
- data/lib/secure_headers/headers/policy_management.rb +410 -0
- data/lib/secure_headers/headers/public_key_pins.rb +5 -4
- data/lib/secure_headers/headers/referrer_policy.rb +37 -0
- data/lib/secure_headers/headers/strict_transport_security.rb +2 -1
- data/lib/secure_headers/headers/x_content_type_options.rb +3 -2
- data/lib/secure_headers/headers/x_download_options.rb +3 -2
- data/lib/secure_headers/headers/x_frame_options.rb +2 -1
- data/lib/secure_headers/headers/x_permitted_cross_domain_policies.rb +3 -2
- data/lib/secure_headers/headers/x_xss_protection.rb +2 -1
- data/lib/secure_headers/middleware.rb +44 -0
- data/lib/secure_headers/railtie.rb +11 -6
- data/lib/secure_headers/utils/cookies_config.rb +95 -0
- data/lib/secure_headers/view_helper.rb +76 -5
- data/lib/secure_headers.rb +159 -99
- data/lib/tasks/tasks.rake +83 -0
- data/secure_headers.gemspec +13 -3
- data/spec/lib/secure_headers/configuration_spec.rb +24 -9
- data/spec/lib/secure_headers/headers/clear_site_data_spec.rb +87 -0
- data/spec/lib/secure_headers/headers/content_security_policy_spec.rb +88 -189
- data/spec/lib/secure_headers/headers/cookie_spec.rb +182 -0
- data/spec/lib/secure_headers/headers/expect_certificate_spec.rb +42 -0
- data/spec/lib/secure_headers/headers/policy_management_spec.rb +228 -0
- data/spec/lib/secure_headers/headers/public_key_pins_spec.rb +7 -6
- data/spec/lib/secure_headers/headers/referrer_policy_spec.rb +73 -0
- data/spec/lib/secure_headers/headers/strict_transport_security_spec.rb +6 -5
- data/spec/lib/secure_headers/headers/x_content_type_options_spec.rb +2 -1
- data/spec/lib/secure_headers/headers/x_download_options_spec.rb +3 -2
- data/spec/lib/secure_headers/headers/x_frame_options_spec.rb +2 -1
- data/spec/lib/secure_headers/headers/x_permitted_cross_domain_policies_spec.rb +4 -3
- data/spec/lib/secure_headers/headers/x_xss_protection_spec.rb +4 -3
- data/spec/lib/secure_headers/middleware_spec.rb +96 -6
- data/spec/lib/secure_headers/view_helpers_spec.rb +138 -0
- data/spec/lib/secure_headers_spec.rb +407 -58
- data/spec/spec_helper.rb +19 -12
- data/upgrading-to-3-0.md +13 -9
- data/upgrading-to-4-0.md +55 -0
- metadata +45 -9
- data/lib/secure_headers/padrino.rb +0 -13
- data/travis.sh +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de4e0f18558ac4a65a9983f56e4dd65ca95e5f82
|
|
4
|
+
data.tar.gz: 3c16a5bdeec36aab812bcbfbbdba544b969c3a33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14f3bc42066b1b4bd6044b75a78818a6ce6edc60760e84af03d13623758a4d05b9397d0c4b4baa92c71d105e0334fa39ec56124c3014e8a63096236f9c6e6d51
|
|
7
|
+
data.tar.gz: f07cfc4d11b24a7d7ec1ad50b2fb756fd3a69c8558b922eb79daf35bbf5dc721c24ca27dfa8b5ca13865dc3345cb0162161f3c41fa04ffbff8c190908d8a7b32
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Feature Requests
|
|
2
|
+
|
|
3
|
+
## Adding a new header
|
|
4
|
+
|
|
5
|
+
Generally, adding a new header is always OK.
|
|
6
|
+
|
|
7
|
+
* Is the header supported by any user agent? If so, which?
|
|
8
|
+
* What does it do?
|
|
9
|
+
* What are the valid values for the header?
|
|
10
|
+
* Where does the specification live?
|
|
11
|
+
|
|
12
|
+
## Adding a new CSP directive
|
|
13
|
+
|
|
14
|
+
* Is the directive supported by any user agent? If so, which?
|
|
15
|
+
* What does it do?
|
|
16
|
+
* What are the valid values for the directive?
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# Bugs
|
|
21
|
+
|
|
22
|
+
Console errors and deprecation warnings are considered bugs that should be addressed with more precise UA sniffing. Bugs caused by incorrect or invalid UA sniffing are also bugs.
|
|
23
|
+
|
|
24
|
+
### Expected outcome
|
|
25
|
+
|
|
26
|
+
Describe what you expected to happen
|
|
27
|
+
|
|
28
|
+
1. I configure CSP to do X
|
|
29
|
+
1. When I inspect the response headers, the CSP should have included X
|
|
30
|
+
|
|
31
|
+
### Actual outcome
|
|
32
|
+
|
|
33
|
+
1. The generated policy did not include X
|
|
34
|
+
|
|
35
|
+
### Config
|
|
36
|
+
|
|
37
|
+
Please provide the configuration (`SecureHeaders::Configuration.default`) you are using including any overrides (`SecureHeaders::Configuration.override`).
|
|
38
|
+
|
|
39
|
+
### Generated headers
|
|
40
|
+
|
|
41
|
+
Provide a sample response containing the headers
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
## All PRs:
|
|
2
|
+
|
|
3
|
+
* [ ] Has tests
|
|
4
|
+
* [ ] Documentation updated
|
|
5
|
+
|
|
6
|
+
## Adding a new header
|
|
7
|
+
|
|
8
|
+
Generally, adding a new header is always OK.
|
|
9
|
+
|
|
10
|
+
* Is the header supported by any user agent? If so, which?
|
|
11
|
+
* What does it do?
|
|
12
|
+
* What are the valid values for the header?
|
|
13
|
+
* Where does the specification live?
|
|
14
|
+
|
|
15
|
+
## Adding a new CSP directive
|
|
16
|
+
|
|
17
|
+
* Is the directive supported by any user agent? If so, which?
|
|
18
|
+
* What does it do?
|
|
19
|
+
* What are the valid values for the directive?
|
|
20
|
+
|
data/.gitignore
CHANGED
|
@@ -6,17 +6,8 @@
|
|
|
6
6
|
.yardoc
|
|
7
7
|
*.log
|
|
8
8
|
Gemfile.lock
|
|
9
|
-
InstalledFiles
|
|
10
9
|
_yardoc
|
|
11
10
|
coverage
|
|
12
|
-
doc/
|
|
13
|
-
lib/bundler/man
|
|
14
11
|
pkg
|
|
15
12
|
rdoc
|
|
16
13
|
spec/reports
|
|
17
|
-
test/tmp
|
|
18
|
-
test/version_tmp
|
|
19
|
-
*tmp
|
|
20
|
-
*.sqlite3
|
|
21
|
-
fixtures/rails_3_2_12_no_init/log
|
|
22
|
-
fixtures/rails_3_2_12/log
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.4.1
|
data/.travis.yml
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
|
|
3
3
|
rvm:
|
|
4
|
-
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
4
|
+
- ruby-head
|
|
5
|
+
- 2.4.1
|
|
6
|
+
- 2.3.4
|
|
7
|
+
- 2.2
|
|
8
|
+
- jruby-head
|
|
9
|
+
|
|
10
|
+
env:
|
|
11
|
+
- SUITE=rspec spec
|
|
12
|
+
- SUITE=rubocop
|
|
13
|
+
|
|
14
|
+
script: bundle exec $SUITE
|
|
15
|
+
|
|
16
|
+
matrix:
|
|
17
|
+
allow_failures:
|
|
18
|
+
- rvm: jruby-head
|
|
19
|
+
- rvm: ruby-head
|
|
9
20
|
|
|
10
21
|
before_install: gem update bundler
|
|
22
|
+
bundler_args: --without guard -j 3
|
|
11
23
|
|
|
12
24
|
sudo: false
|
|
13
25
|
cache: bundler
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,289 @@
|
|
|
1
|
+
## 4.x
|
|
2
|
+
|
|
3
|
+
- See the [upgrading to 4.0](upgrading-to-4-0.md) guide. Lots of breaking changes.
|
|
4
|
+
|
|
5
|
+
## 3.7.1
|
|
6
|
+
|
|
7
|
+
Fix support for the sandbox attribute of CSP. `true` and `[]` represent the maximally restricted policy (`sandbox;`) and validate other values.
|
|
8
|
+
|
|
9
|
+
## 3.7.0
|
|
10
|
+
|
|
11
|
+
Adds support for the `Expect-CT` header (@jacobbednarz: https://github.com/twitter/secureheaders/pull/322)
|
|
12
|
+
|
|
13
|
+
## 3.6.7
|
|
14
|
+
|
|
15
|
+
Actually set manifest-src when configured. https://github.com/twitter/secureheaders/pull/339 Thanks @carlosantoniodasilva!
|
|
16
|
+
|
|
17
|
+
## 3.6.5
|
|
18
|
+
|
|
19
|
+
Update clear-site-data header to use current format specified by the specification.
|
|
20
|
+
|
|
21
|
+
## 3.6.4
|
|
22
|
+
|
|
23
|
+
Fix case where mixing frame-src/child-src dynamically would behave in unexpected ways: https://github.com/twitter/secureheaders/pull/325
|
|
24
|
+
|
|
25
|
+
## 3.6.3
|
|
26
|
+
|
|
27
|
+
Remove deprecation warning when setting `frame-src`. It is no longer deprecated.
|
|
28
|
+
|
|
29
|
+
## 3.6.2
|
|
30
|
+
|
|
31
|
+
Now that Safari 10 supports nonces and it appears to work, enable the nonce feature for safari.
|
|
32
|
+
|
|
33
|
+
## 3.6.1
|
|
34
|
+
|
|
35
|
+
Improved memory use via minor improvements clever hacks that are sadly needed.
|
|
36
|
+
Thanks @carlosantoniodasilva!
|
|
37
|
+
|
|
38
|
+
## 3.6.0
|
|
39
|
+
|
|
40
|
+
Add support for the clear-site-data header
|
|
41
|
+
|
|
42
|
+
## 3.5.1
|
|
43
|
+
|
|
44
|
+
* Fix bug that can occur when useragent library version is older, resulting in a nil version sometimes.
|
|
45
|
+
* Add constant for `strict-dynamic`
|
|
46
|
+
|
|
47
|
+
## 3.5.0
|
|
48
|
+
|
|
49
|
+
This release adds support for setting two CSP headers (enforced/report-only) and management around them.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## 3.4.1 Named Appends
|
|
53
|
+
|
|
54
|
+
### Small bugfix
|
|
55
|
+
|
|
56
|
+
If your CSP did not define a script/style-src and you tried to use a script/style nonce, the nonce would be added to the page but it would not be added to the CSP. A workaround is to define a script/style src but now it should add the missing directive (and populate it with the default-src).
|
|
57
|
+
|
|
58
|
+
### Named Appends
|
|
59
|
+
|
|
60
|
+
Named Appends are blocks of code that can be reused and composed during requests. e.g. If a certain partial is rendered conditionally, and the csp needs to be adjusted for that partial, you can create a named append for that situation. The value returned by the block will be passed into `append_content_security_policy_directives`. The current request object is passed as an argument to the block for even more flexibility.
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
def show
|
|
64
|
+
if include_widget?
|
|
65
|
+
@widget = widget.render
|
|
66
|
+
use_content_security_policy_named_append(:widget_partial)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
SecureHeaders::Configuration.named_append(:widget_partial) do |request|
|
|
72
|
+
if request.controller_instance.current_user.in_test_bucket?
|
|
73
|
+
SecureHeaders.override_x_frame_options(request, "DENY")
|
|
74
|
+
{ child_src: %w(beta.thirdpartyhost.com) }
|
|
75
|
+
else
|
|
76
|
+
{ child_src: %w(thirdpartyhost.com) }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
You can use as many named appends as you would like per request, but be careful because order of inclusion matters. Consider the following:
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
SecureHeader::Configuration.default do |config|
|
|
85
|
+
config.csp = { default_src: %w('self')}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
SecureHeaders::Configuration.named_append(:A) do |request|
|
|
89
|
+
{ default_src: %w(myhost.com) }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
SecureHeaders::Configuration.named_append(:B) do |request|
|
|
93
|
+
{ script_src: %w('unsafe-eval') }
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The following code will produce different policies due to the way policies are normalized (e.g. providing a previously undefined directive that inherits from `default-src`, removing host source values when `*` is provided. Removing `'none'` when additional values are present, etc.):
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
def index
|
|
101
|
+
use_content_security_policy_named_append(:A)
|
|
102
|
+
use_content_security_policy_named_append(:B)
|
|
103
|
+
# produces default-src 'self' myhost.com; script-src 'self' myhost.com 'unsafe-eval';
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def show
|
|
107
|
+
use_content_security_policy_named_append(:B)
|
|
108
|
+
use_content_security_policy_named_append(:A)
|
|
109
|
+
# produces default-src 'self' myhost.com; script-src 'self' 'unsafe-eval';
|
|
110
|
+
end
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## 3.4.0 the frame-src/child-src transition for Firefox.
|
|
114
|
+
|
|
115
|
+
Handle the `child-src`/`frame-src` transition semi-intelligently across versions. I think the code best descibes the behavior here:
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
if supported_directives.include?(:child_src)
|
|
119
|
+
@config[:child_src] = @config[:child_src] || @config[:frame_src]
|
|
120
|
+
else
|
|
121
|
+
@config[:frame_src] = @config[:frame_src] || @config[:child_src]
|
|
122
|
+
end
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Also, @koenpunt noticed that we were [loading view helpers](https://github.com/twitter/secureheaders/pull/272) in a way that Rails 5 did not like.
|
|
126
|
+
|
|
127
|
+
## 3.3.2 minor fix to silence warnings when using rake
|
|
128
|
+
|
|
129
|
+
[@dankohn](https://github.com/twitter/secureheaders/issues/257) was seeing "already initialized" errors in his output. This change conditionally defines the constants.
|
|
130
|
+
|
|
131
|
+
## 3.3.1 bugfix for boolean CSP directives
|
|
132
|
+
|
|
133
|
+
[@stefansundin](https://github.com/twitter/secureheaders/pull/253) noticed that supplying `false` to "boolean" CSP directives (e.g. `upgrade-insecure-requests` and `block-all-mixed-content`) would still include the value.
|
|
134
|
+
|
|
135
|
+
## 3.3.0 referrer-policy support
|
|
136
|
+
|
|
137
|
+
While not officially part of the spec and not implemented anywhere, support for the experimental [`referrer-policy` header](https://w3c.github.io/webappsec-referrer-policy/#referrer-policy-header) was [preemptively added](https://github.com/twitter/secureheaders/pull/249).
|
|
138
|
+
|
|
139
|
+
Additionally, two minor enhancements were added this version:
|
|
140
|
+
1. [Warn when the HPKP report host is the same as the current host](https://github.com/twitter/secureheaders/pull/246). By definition any generated reports would be reporting to a known compromised connection.
|
|
141
|
+
1. [Filter unsupported CSP directives when using Edge](https://github.com/twitter/secureheaders/pull/247). Previously, this was causing many warnings in the developer console.
|
|
142
|
+
|
|
143
|
+
## 3.2.0 Cookie settings and CSP hash sources
|
|
144
|
+
|
|
145
|
+
### Cookies
|
|
146
|
+
|
|
147
|
+
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.
|
|
148
|
+
|
|
149
|
+
__Note__: Regardless of the configuration specified, Secure cookies are only enabled for HTTPS requests.
|
|
150
|
+
|
|
151
|
+
#### Boolean-based configuration
|
|
152
|
+
|
|
153
|
+
Boolean-based configuration is intended to globally enable or disable a specific cookie attribute.
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
config.cookies = {
|
|
157
|
+
secure: true, # mark all cookies as Secure
|
|
158
|
+
httponly: false, # do not mark any cookies as HttpOnly
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Hash-based configuration
|
|
163
|
+
|
|
164
|
+
Hash-based configuration allows for fine-grained control.
|
|
165
|
+
|
|
166
|
+
```ruby
|
|
167
|
+
config.cookies = {
|
|
168
|
+
secure: { except: ['_guest'] }, # mark all but the `_guest` cookie as Secure
|
|
169
|
+
httponly: { only: ['_rails_session'] }, # only mark the `_rails_session` cookie as HttpOnly
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### SameSite cookie configuration
|
|
174
|
+
|
|
175
|
+
SameSite cookies permit either `Strict` or `Lax` enforcement mode options.
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
config.cookies = {
|
|
179
|
+
samesite: {
|
|
180
|
+
strict: true # mark all cookies as SameSite=Strict
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
`Strict` and `Lax` enforcement modes can also be specified using a Hash.
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
config.cookies = {
|
|
189
|
+
samesite: {
|
|
190
|
+
strict: { only: ['_rails_session'] },
|
|
191
|
+
lax: { only: ['_guest'] }
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Hash
|
|
197
|
+
|
|
198
|
+
`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`.
|
|
199
|
+
|
|
200
|
+
You can add hash sources directly to your policy :
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
::SecureHeaders::Configuration.default do |config|
|
|
204
|
+
config.csp = {
|
|
205
|
+
default_src: %w('self')
|
|
206
|
+
|
|
207
|
+
# this is a made up value but browsers will show the expected hash in the console.
|
|
208
|
+
script_src: %w(sha256-123456)
|
|
209
|
+
}
|
|
210
|
+
end
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
You can also use the automated inline script detection/collection/computation of hash source values in your app.
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
rake secure_headers:generate_hashes
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
This will generate a file (`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.
|
|
220
|
+
|
|
221
|
+
```yaml
|
|
222
|
+
---
|
|
223
|
+
scripts:
|
|
224
|
+
app/views/asdfs/index.html.erb:
|
|
225
|
+
- "'sha256-yktKiAsZWmc8WpOyhnmhQoDf9G2dAZvuBBC+V0LGQhg='"
|
|
226
|
+
styles:
|
|
227
|
+
app/views/asdfs/index.html.erb:
|
|
228
|
+
- "'sha256-SLp6LO3rrKDJwsG9uJUxZapb4Wp2Zhj6Bu3l+d9rnAY='"
|
|
229
|
+
- "'sha256-HSGHqlRoKmHAGTAJ2Rq0piXX4CnEbOl1ArNd6ejp2TE='"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
##### Helpers
|
|
233
|
+
|
|
234
|
+
**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.
|
|
235
|
+
|
|
236
|
+
```erb
|
|
237
|
+
<%= hashed_style_tag do %>
|
|
238
|
+
body {
|
|
239
|
+
background-color: black;
|
|
240
|
+
}
|
|
241
|
+
<% end %>
|
|
242
|
+
|
|
243
|
+
<%= hashed_style_tag do %>
|
|
244
|
+
body {
|
|
245
|
+
font-size: 30px;
|
|
246
|
+
font-color: green;
|
|
247
|
+
}
|
|
248
|
+
<% end %>
|
|
249
|
+
|
|
250
|
+
<%= hashed_javascript_tag do %>
|
|
251
|
+
console.log(1)
|
|
252
|
+
<% end %>
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
Content-Security-Policy: ...
|
|
257
|
+
script-src 'sha256-yktKiAsZWmc8WpOyhnmhQoDf9G2dAZvuBBC+V0LGQhg=' ... ;
|
|
258
|
+
style-src 'sha256-SLp6LO3rrKDJwsG9uJUxZapb4Wp2Zhj6Bu3l+d9rnAY=' 'sha256-HSGHqlRoKmHAGTAJ2Rq0piXX4CnEbOl1ArNd6ejp2TE=' ...;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 3.1.2 Bug fix for regression
|
|
262
|
+
|
|
263
|
+
See https://github.com/twitter/secureheaders/pull/239
|
|
264
|
+
|
|
265
|
+
This meant that when header caches were regenerated upon calling `SecureHeaders.override(:name)` and using it with `use_secure_headers_override` would result in default values for anything other than CSP/HPKP.
|
|
266
|
+
|
|
267
|
+
## 3.1.1 Bug fix for regression
|
|
268
|
+
|
|
269
|
+
See https://github.com/twitter/secureheaders/pull/235
|
|
270
|
+
|
|
271
|
+
`idempotent_additions?` would return false when comparing `OPT_OUT` with `OPT_OUT`, causing `header_hash_for` to return a header cache with `{ nil => nil }` which cause the middleware to blow up when `{ nil => nil }` was merged into the rack header hash.
|
|
272
|
+
|
|
273
|
+
This is a regression in 3.1.0 only.
|
|
274
|
+
|
|
275
|
+
Now it returns true. I've added a test case to ensure that `header_hash_for` will never return such an element.
|
|
276
|
+
|
|
277
|
+
## 3.1.0 Adding secure cookie support
|
|
278
|
+
|
|
279
|
+
New feature: marking all cookies as secure. Added by @jmera in https://github.com/twitter/secureheaders/pull/231. In the future, we'll probably add the ability to whitelist individual cookies that should not be marked secure. PRs welcome.
|
|
280
|
+
|
|
281
|
+
Internal refactoring: In https://github.com/twitter/secureheaders/pull/232, we changed the way dynamic CSP is handled internally. The biggest benefit is that highly dynamic policies (which can happen with multiple `append/override` calls per request) are handled better:
|
|
282
|
+
|
|
283
|
+
1. Only the CSP header cache is busted when using a dynamic policy. All other headers are preserved and don't need to be generated. Dynamic X-Frame-Options changes modify the cache directly.
|
|
284
|
+
1. Idempotency checks for policy modifications are deferred until the end of the request lifecycle and only happen once, instead of per `append/override` call. The idempotency check itself is fairly expensive itself.
|
|
285
|
+
1. CSP header string is produced at most once per request.
|
|
286
|
+
|
|
1
287
|
## 3.0.3
|
|
2
288
|
|
|
3
289
|
Bug fix for handling policy merges where appending a non-default source value (report-uri, plugin-types, frame-ancestors, base-uri, and form-action) would be combined with the default-src value. Appending a directive that doesn't exist in the current policy combines the new value with `default-src` to mimic the actual behavior of the addition. However, this does not make sense for non-default-src values (a.k.a. "fetch directives") and can lead to unexpected behavior like a `report-uri` value of `*`. Previously, this config:
|
|
@@ -14,6 +300,7 @@ When appending:
|
|
|
14
300
|
{
|
|
15
301
|
report_uri => %w(https://report-uri.io/asdf)
|
|
16
302
|
}
|
|
303
|
+
```
|
|
17
304
|
|
|
18
305
|
Would result in `default-src *; report-uri *` which doesn't make any sense at all.
|
|
19
306
|
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
## Our Standards
|
|
8
|
+
|
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
|
10
|
+
|
|
11
|
+
* Using welcoming and inclusive language
|
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
|
13
|
+
* Gracefully accepting constructive criticism
|
|
14
|
+
* Focusing on what is best for the community
|
|
15
|
+
* Showing empathy towards other community members
|
|
16
|
+
|
|
17
|
+
Examples of unacceptable behavior by participants include:
|
|
18
|
+
|
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
21
|
+
* Public or private harassment
|
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
24
|
+
|
|
25
|
+
## Our Responsibilities
|
|
26
|
+
|
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
|
28
|
+
|
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
|
30
|
+
|
|
31
|
+
## Scope
|
|
32
|
+
|
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
|
34
|
+
|
|
35
|
+
## Enforcement
|
|
36
|
+
|
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at neil.matatall@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
|
38
|
+
|
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
|
40
|
+
|
|
41
|
+
## Attribution
|
|
42
|
+
|
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
|
44
|
+
|
|
45
|
+
[homepage]: http://contributor-covenant.org
|
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
## Contributing
|
|
2
|
+
|
|
3
|
+
[fork]: https://github.com/twitter/secureheaders/fork
|
|
4
|
+
[pr]: https://github.com/twitter/secureheaders/compare
|
|
5
|
+
[style]: https://github.com/styleguide/ruby
|
|
6
|
+
[code-of-conduct]: CODE_OF_CONDUCT.md
|
|
7
|
+
|
|
8
|
+
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
|
|
9
|
+
|
|
10
|
+
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
|
|
11
|
+
|
|
12
|
+
## Submitting a pull request
|
|
13
|
+
|
|
14
|
+
0. [Fork][fork] and clone the repository
|
|
15
|
+
0. Configure and install the dependencies: `bundle install`
|
|
16
|
+
0. Make sure the tests pass on your machine: `bundle exec rspec spec`
|
|
17
|
+
0. Create a new branch: `git checkout -b my-branch-name`
|
|
18
|
+
0. Make your change, add tests, and make sure the tests still pass and that no warnings are raised
|
|
19
|
+
0. Push to your fork and [submit a pull request][pr]
|
|
20
|
+
0. Pat your self on the back and wait for your pull request to be reviewed and merged.
|
|
21
|
+
|
|
22
|
+
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
|
|
23
|
+
|
|
24
|
+
- Write tests.
|
|
25
|
+
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
|
|
26
|
+
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
|
|
27
|
+
|
|
28
|
+
## Releasing
|
|
29
|
+
|
|
30
|
+
0. Ensure CI is green
|
|
31
|
+
0. Pull the latest code
|
|
32
|
+
0. Increment the version
|
|
33
|
+
0. Run `gem build secure_headers.gemspec`
|
|
34
|
+
0. Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem
|
|
35
|
+
0. Test behavior locally, branch deploy, whatever needs to happen
|
|
36
|
+
0. Run `bundle exec rake release`
|
|
37
|
+
|
|
38
|
+
## Resources
|
|
39
|
+
|
|
40
|
+
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
|
41
|
+
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
|
data/Gemfile
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
source "https://rubygems.org"
|
|
2
3
|
|
|
3
4
|
gemspec
|
|
4
5
|
|
|
5
6
|
group :test do
|
|
6
|
-
gem "
|
|
7
|
+
gem "coveralls"
|
|
8
|
+
gem "json", "~> 1"
|
|
7
9
|
gem "pry-nav"
|
|
8
|
-
gem "rack"
|
|
9
|
-
gem "
|
|
10
|
-
gem "
|
|
10
|
+
gem "rack", "~> 1"
|
|
11
|
+
gem "rspec"
|
|
12
|
+
gem "rubocop", "~> 0.47.0"
|
|
13
|
+
gem "rubocop-github"
|
|
14
|
+
gem "term-ansicolor", "< 1.4"
|
|
15
|
+
gem "tins", "~> 1.6.0" # 1.7 requires ruby 2.0
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
group :guard do
|
|
11
19
|
gem "growl"
|
|
20
|
+
gem "guard-rspec", platforms: [:ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24]
|
|
12
21
|
gem "rb-fsevent"
|
|
13
|
-
gem "coveralls", platforms: [:ruby_19, :ruby_20, :ruby_21, :ruby_22]
|
|
14
22
|
end
|
data/Guardfile
CHANGED