secure_headers 1.3.4 → 2.0.0.pre

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.
Files changed (65) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +4 -8
  3. data/.travis.yml +0 -3
  4. data/Gemfile +4 -5
  5. data/Guardfile +4 -2
  6. data/README.md +102 -48
  7. data/Rakefile +0 -116
  8. data/fixtures/rails_3_2_12/Gemfile +0 -5
  9. data/fixtures/rails_3_2_12/app/controllers/things_controller.rb +0 -1
  10. data/fixtures/rails_3_2_12/app/views/layouts/application.html.erb +1 -4
  11. data/fixtures/rails_3_2_12/app/views/other_things/index.html.erb +2 -1
  12. data/fixtures/rails_3_2_12/config/application.rb +0 -54
  13. data/fixtures/rails_3_2_12/config/initializers/secure_headers.rb +1 -1
  14. data/fixtures/rails_3_2_12/config/routes.rb +0 -57
  15. data/fixtures/rails_3_2_12/config/script_hashes.yml +5 -0
  16. data/fixtures/rails_3_2_12/config.ru +3 -0
  17. data/fixtures/rails_3_2_12/spec/controllers/other_things_controller_spec.rb +50 -18
  18. data/fixtures/rails_3_2_12/spec/controllers/things_controller_spec.rb +1 -1
  19. data/fixtures/rails_3_2_12_no_init/Gemfile +0 -6
  20. data/fixtures/rails_3_2_12_no_init/app/controllers/other_things_controller.rb +1 -2
  21. data/fixtures/rails_3_2_12_no_init/app/controllers/things_controller.rb +1 -1
  22. data/fixtures/rails_3_2_12_no_init/app/views/layouts/application.html.erb +0 -2
  23. data/fixtures/rails_3_2_12_no_init/app/views/things/index.html.erb +0 -21
  24. data/fixtures/rails_3_2_12_no_init/config/application.rb +0 -48
  25. data/fixtures/rails_3_2_12_no_init/config/routes.rb +0 -57
  26. data/lib/secure_headers/hash_helper.rb +7 -0
  27. data/lib/secure_headers/headers/content_security_policy/script_hash_middleware.rb +22 -0
  28. data/lib/secure_headers/headers/content_security_policy.rb +141 -133
  29. data/lib/secure_headers/railtie.rb +0 -22
  30. data/lib/secure_headers/version.rb +1 -1
  31. data/lib/secure_headers/view_helper.rb +68 -0
  32. data/lib/secure_headers.rb +50 -16
  33. data/lib/tasks/tasks.rake +48 -0
  34. data/spec/lib/secure_headers/headers/content_security_policy/script_hash_middleware_spec.rb +47 -0
  35. data/spec/lib/secure_headers/headers/content_security_policy_spec.rb +83 -208
  36. data/spec/lib/secure_headers_spec.rb +16 -62
  37. data/spec/spec_helper.rb +25 -1
  38. metadata +19 -40
  39. data/HISTORY.md +0 -162
  40. data/app/controllers/content_security_policy_controller.rb +0 -75
  41. data/config/curl-ca-bundle.crt +0 -5420
  42. data/config/routes.rb +0 -3
  43. data/fixtures/rails_3_2_12/config/environments/development.rb +0 -37
  44. data/fixtures/rails_3_2_12/config/environments/production.rb +0 -67
  45. data/fixtures/rails_3_2_12/config/initializers/backtrace_silencers.rb +0 -7
  46. data/fixtures/rails_3_2_12/config/initializers/inflections.rb +0 -15
  47. data/fixtures/rails_3_2_12/config/initializers/mime_types.rb +0 -5
  48. data/fixtures/rails_3_2_12/config/initializers/secret_token.rb +0 -7
  49. data/fixtures/rails_3_2_12/config/initializers/session_store.rb +0 -8
  50. data/fixtures/rails_3_2_12/config/initializers/wrap_parameters.rb +0 -14
  51. data/fixtures/rails_3_2_12/config/locales/en.yml +0 -5
  52. data/fixtures/rails_3_2_12_no_init/app/views/things/_form.html.erb +0 -17
  53. data/fixtures/rails_3_2_12_no_init/app/views/things/edit.html.erb +0 -6
  54. data/fixtures/rails_3_2_12_no_init/app/views/things/new.html.erb +0 -5
  55. data/fixtures/rails_3_2_12_no_init/app/views/things/show.html.erb +0 -5
  56. data/fixtures/rails_3_2_12_no_init/config/environments/development.rb +0 -37
  57. data/fixtures/rails_3_2_12_no_init/config/environments/production.rb +0 -67
  58. data/fixtures/rails_3_2_12_no_init/config/initializers/backtrace_silencers.rb +0 -7
  59. data/fixtures/rails_3_2_12_no_init/config/initializers/inflections.rb +0 -15
  60. data/fixtures/rails_3_2_12_no_init/config/initializers/mime_types.rb +0 -5
  61. data/fixtures/rails_3_2_12_no_init/config/initializers/secret_token.rb +0 -7
  62. data/fixtures/rails_3_2_12_no_init/config/initializers/session_store.rb +0 -8
  63. data/fixtures/rails_3_2_12_no_init/config/initializers/wrap_parameters.rb +0 -14
  64. data/fixtures/rails_3_2_12_no_init/config/locales/en.yml +0 -5
  65. data/spec/controllers/content_security_policy_controller_spec.rb +0 -90
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzcxMzdhM2IwMTAxN2IyNTc5OTg5OGY1MmJlZGFlNWJmNjBjM2MzMw==
5
- data.tar.gz: !binary |-
6
- ODNmNjA1YmY1ODEzMWIxYTU2YWYzYmY3NGFjM2Y1ZDU4MDQ0ODkwMQ==
2
+ SHA1:
3
+ metadata.gz: 4d41b253fa38de884f864558563330b9e707e2dc
4
+ data.tar.gz: 69b19dbc4ab124481e6f47dad73cd7a6497aa844
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NGEwNTVlZjBmMTcwN2QxYjI5YjVkZGJhZmJiYTJlY2M3YzEyM2JiN2Q3MzY0
10
- NzdmNWNhMDIzMmVhNzNkZWRmZTZiYmQ1OWE5MjMwYTY2MDE1NGVhMWU3Mjg4
11
- OTdmZTZiOGI0N2NhNGYzZThkMjc3ZWYxMjU5YzhiYTNjNmFmZjE=
12
- data.tar.gz: !binary |-
13
- MTI1NTNhYzExYjVmYjMwNjNjMGUzMDlmYmVmZTk1YjJiN2UwODM4MzYwNzhj
14
- Y2ZhMzYxNTNkM2Y0MWY1YTQ1ZWMyYmQ4NDA3NjJhOGViNTU0MmEwYWY4MTNm
15
- MTczMzNjOTliYWYzODFiY2RiNDZmOGQ2ZWU4ZjdiNWJhMTZlMzA=
6
+ metadata.gz: fa7e778e7cb305a3273d4b3aa94bf8597972910da752b218ebf0779330c4c025c2906cec3974a410193db600fc899465a2da8bc7a8ca5720eb30ba95335e7a5d
7
+ data.tar.gz: 21934fb364794d3fc08e7dde201e04cb1253686e362e46ec370b06021007cb897fc3182de9a1ac646fa2448f4ce7a9f45b33da31f4d2a8690b76c42527bb9001
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ *.DS_STORE
2
3
  *.rbc
3
4
  .bundle
4
5
  .config
@@ -15,12 +16,7 @@ rdoc
15
16
  spec/reports
16
17
  test/tmp
17
18
  test/version_tmp
18
- tmp
19
-
20
- /fixtures/rails_3_2_12/log/test.log
21
- /fixtures/rails_3_2_12_no_init/log/test.log
19
+ *tmp
22
20
  *.sqlite3
23
- test.sqlite3
24
- *test.sqlite3
25
- /fixtures/rails_3_2_12_no_init/db/test.sqlite3
26
- /fixtures/rails_3_2_12/db/test.sqlite3
21
+ fixtures/rails_3_2_12_no_init/log
22
+ fixtures/rails_3_2_12/log
data/.travis.yml CHANGED
@@ -3,6 +3,3 @@ rvm:
3
3
  - "2.0.0"
4
4
  - "1.9.3"
5
5
  - "1.8.7"
6
- # - jruby-19mode
7
- # - jruby-18mode
8
- #script: ./travis.sh
data/Gemfile CHANGED
@@ -6,11 +6,10 @@ group :test do
6
6
  gem 'rails', '3.2.12'
7
7
  gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
8
8
  gem 'jdbc-sqlite3', :platform => :jruby
9
- gem 'rspec-rails'
10
- gem 'rspec'
11
- gem 'guard-rspec', :platform => :ruby_19
9
+ gem 'rspec-rails', '>= 3.1'
10
+ gem 'rspec', '>= 3.1'
11
+ gem 'guard-rspec', :platform => [:ruby_19, :ruby_20, :ruby_21]
12
12
  gem 'growl'
13
13
  gem 'rb-fsevent'
14
- gem 'debugger', :platform => :ruby_19
15
- gem 'ruby-debug', :platform => :ruby_18
14
+ gem 'coveralls', :platform => :ruby_19
16
15
  end
data/Guardfile CHANGED
@@ -1,6 +1,8 @@
1
- guard 'rspec' do
1
+ notification :growl
2
+
3
+ guard 'rspec', cmd: 'rspec' do
2
4
  watch(%r{^spec/.+_spec\.rb$})
3
5
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
6
  watch(%r{^app/controllers/(.+)\.rb$}) { |m| "spec/controllers/#{m[1]}_spec.rb" }
5
7
  watch('spec/spec_helper.rb') { "spec" }
6
- end
8
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SecureHeaders [![Build Status](https://travis-ci.org/twitter/secureheaders.png?branch=master)](http://travis-ci.org/twitter/secureheaders) [![Code Climate](https://codeclimate.com/github/twitter/secureheaders.png)](https://codeclimate.com/github/twitter/secureheaders)
1
+ # SecureHeaders [![Build Status](https://travis-ci.org/twitter/secureheaders.png?branch=master)](http://travis-ci.org/twitter/secureheaders) [![Code Climate](https://codeclimate.com/github/twitter/secureheaders.png)](https://codeclimate.com/github/twitter/secureheaders) [![Coverage Status](https://coveralls.io/repos/twitter/secureheaders/badge.png)](https://coveralls.io/r/twitter/secureheaders)
2
2
 
3
3
  The gem will automatically apply several headers that are related to security. This includes:
4
4
  - Content Security Policy (CSP) - Helps detect/prevent XSS, mixed-content, and other classes of attack. [CSP 1.1 Specification](https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html)
@@ -54,8 +54,6 @@ The following methods are going to be called, unless they are provided in a `ski
54
54
  This gem makes a few assumptions about how you will use some features. For example:
55
55
 
56
56
  * It fills any blank directives with the value in `:default_src` Getting a default\-src report is pretty useless. This way, you will always know what type of violation occurred. You can disable this feature by supplying `:disable_fill_missing => true`. This is referred to as the "effective-directive" in the spec, but is not well supported as of Nov 5, 2013.
57
- * Firefox does not support cross\-origin CSP reports. If we are using Firefox, AND the value for `:report_uri` does not satisfy the same\-origin requirements, we will instead forward to an internal endpoint (`FF_CSP_ENDPOINT`). This is also the case if `:report_uri` only contains a path, which we assume will be cross host. This endpoint will in turn forward the request to the value in `:forward_endpoint` without restriction. More information can be found in the "Note on Firefox handling of CSP" section.
58
-
59
57
 
60
58
  ## Configuration
61
59
 
@@ -68,9 +66,9 @@ This gem makes a few assumptions about how you will use some features. For exam
68
66
  config.x_content_type_options = "nosniff"
69
67
  config.x_xss_protection = {:value => 1, :mode => 'block'}
70
68
  config.csp = {
71
- :default_src => "https://* self",
72
- :frame_src => "https://* http://*.twimg.com http://itunes.apple.com",
73
- :img_src => "https://*",
69
+ :default_src => "https: self",
70
+ :frame_src => "https: http:.twimg.com http://itunes.apple.com",
71
+ :img_src => "https:",
74
72
  :report_uri => '//example.com/uri-directive'
75
73
  }
76
74
  end
@@ -125,11 +123,6 @@ and [Mozilla CSP specification](https://wiki.mozilla.org/Security/CSP/Specificat
125
123
  # Where reports are sent. Use protocol relative URLs if you are posting to the same domain (TLD+1). Use paths if you are posting to the application serving the header
126
124
  :report_uri => '//mysite.example.com',
127
125
 
128
- # Send reports that cannot be sent across host here. These requests are sent
129
- # the server, not the browser. If no value is supplied, it will default to
130
- # the value in report_uri. Use this if you cannot use relative protocols mentioned above due to host mismatches.
131
- :forward_endpoint => 'https://internal.mylogaggregator.example.com'
132
-
133
126
  # these directives all take 'none', 'self', or a globbed pattern
134
127
  :img_src => nil,
135
128
  :frame_src => nil,
@@ -144,25 +137,12 @@ and [Mozilla CSP specification](https://wiki.mozilla.org/Security/CSP/Specificat
144
137
  # over http, relaxing the policy
145
138
  # e.g.
146
139
  # :csp => {
147
- # :img_src => 'https://*',
148
- # :http_additions => {:img_src => 'http//*'}
140
+ # :img_src => 'https:',
141
+ # :http_additions => {:img_src => 'http'}
149
142
  # }
150
- # would produce the directive: "img-src https://* http://*;"
143
+ # would produce the directive: "img-src https: http:;"
151
144
  # when over http, ignored for https requests
152
145
  :http_additions => {}
153
-
154
- # If you have enforce => true, you can use the `experiments` block to
155
- # also produce a report-only header. Values in this block override the
156
- # parent config for the report-only, and leave the enforcing header
157
- # unaltered. http_additions work the same way described above, but
158
- # are added to your report-only header as expected.
159
- :experimental => {
160
- :script_src => 'self',
161
- :img_src => 'https://mycdn.example.com',
162
- :http_additions {
163
- :img_src => 'http://mycdn.example.com'
164
- }
165
- }
166
146
  }
167
147
  ```
168
148
 
@@ -172,19 +152,19 @@ and [Mozilla CSP specification](https://wiki.mozilla.org/Security/CSP/Specificat
172
152
  ```ruby
173
153
  # most basic example
174
154
  :csp => {
175
- :default_src => "https://* inline eval",
155
+ :default_src => "https: inline eval",
176
156
  :report_uri => '/uri-directive'
177
157
  }
178
158
 
179
- > "default-src 'unsafe-inline' 'unsafe-eval' https://*; report-uri /uri-directive;"
159
+ > "default-src 'unsafe-inline' 'unsafe-eval' https:; report-uri /uri-directive;"
180
160
 
181
161
  # turn off inline scripting/eval
182
162
  :csp => {
183
- :default_src => 'https://*',
163
+ :default_src => 'https:',
184
164
  :report_uri => '/uri-directive'
185
165
  }
186
166
 
187
- > "default-src https://*; report-uri /uri-directive;"
167
+ > "default-src https:; report-uri /uri-directive;"
188
168
 
189
169
  # Auction site wants to allow images from anywhere, plugin content from a list of trusted media providers (including a content distribution network), and scripts only from its server hosting sanitized JavaScript
190
170
  :csp => {
@@ -217,9 +197,13 @@ report-uri csp_reports?enforce=true&app_name=twitter
217
197
 
218
198
  ### CSP Level 2 features
219
199
 
200
+ *NOTE: Currently, only erb is supported. Mustache support isn't far off. Hash sources are valid for inline style blocks but are not yet supported by secure_headers.*
201
+
202
+ #### Nonce
203
+
220
204
  script/style-nonce can be used to whitelist inline content. To do this, add "nonce" to your script/style-src configuration, then set the nonce attributes on the various tags.
221
205
 
222
- *setting a nonce will also set 'unsafe-inline' for browsers that don't support nonces for backwards compatibility. 'unsafe-inline' is ignored if a nonce is present in a directive in compliant browsers.
206
+ Setting a nonce will also set 'unsafe-inline' for browsers that don't support nonces for backwards compatibility. 'unsafe-inline' is ignored if a nonce is present in a directive in compliant browsers.
223
207
 
224
208
  ```ruby
225
209
  :csp => {
@@ -243,29 +227,99 @@ script/style-nonce can be used to whitelist inline content. To do this, add "non
243
227
  console.log("won't execute, not whitelisted")
244
228
  </script>
245
229
  ```
230
+ You can use a view helper to automatically add nonces to script tags:
231
+ ```erb
232
+ <%= nonced_javascript_tag do %>
233
+ console.log("nonced!")
234
+ <% end %>
235
+ <%= nonced_javascript_tag("nonced without a block!") %>
236
+ ```
246
237
 
247
- ## Note on Firefox handling of CSP
238
+ becomes:
248
239
 
249
- * CSP reports will not POST cross\-origin. This sets up an internal endpoint in the application that will forward the request. Set the `forward_endpoint` value in the CSP section if you need to post cross origin for firefox. The internal endpoint that receives the initial request will forward the request to `forward_endpoint`
240
+ ```html
241
+ <script nonce="/jRAxuLJsDXAxqhNBB7gg7h55KETtDQBXe4ZL+xIXwI=">
242
+ console.log("nonced!")
243
+ </script>
244
+ ```
245
+
246
+ #### Hash
250
247
 
251
- ### Adding the Firefox report forwarding endpoint
248
+ setting hash source values will also set 'unsafe-inline' for browsers that don't support hash sources for backwards compatibility. 'unsafe-inline' is ignored if a hash is present in a directive in compliant browsers.
252
249
 
253
- **You need to add the following line to the TOP of confib/routes.rb**
254
- **This is an unauthenticated, unauthorized endpoint. Only do this if your report\-uri is not on the same origin as your application!!!**
250
+ Hash source support works by taking the hash value of the contents of an inline script block and adding the hash "fingerprint" to the CSP header.
255
251
 
256
- #### Rails 2
252
+ If you only have a few hashes, you can hardcode them for the entire app:
257
253
 
258
254
  ```ruby
259
- map.csp_endpoint
255
+ config.csp = {
256
+ :default_src => "https:",
257
+ :script_src => 'self'
258
+ :script_hashes => ['sha1-abc', 'sha1-qwe']
259
+ }
260
260
  ```
261
261
 
262
- #### Rails 3
262
+ The following will work as well, but may not be as clear:
263
+
264
+ ```ruby
265
+ config.csp = {
266
+ :default_src => "https:",
267
+ :script_src => "self 'sha1-qwe'"
268
+ }
269
+ ```
263
270
 
264
- If the csp reporting endpoint is clobbered by another route, add:
271
+ If you find you have many hashes or the content of the script tags change frequently, you can apply these hashes in a more intelligent way. This method expects config/script_hashes.yml to contain a map of templates => [hashes]. When the individual templates, layouts, or partials are rendered the hash values for the script tags in those templates will be automatically added to the header. *Currently, only erb layouts are supported.* This requires the use of middleware:
265
272
 
266
273
  ```ruby
267
- post SecureHeaders::ContentSecurityPolicy::FF_CSP_ENDPOINT => "content_security_policy#scribe"
274
+ # config.ru
275
+ require 'secure_headers/headers/content_security_policy/script_hash_middleware'
276
+ use ::SecureHeaders::ContentSecurityPolicy::ScriptHashMiddleware
268
277
  ```
278
+
279
+ ```ruby
280
+ config.csp = {
281
+ :default_src => "https:",
282
+ :script_src => 'self',
283
+ :script_hash_middleware => true
284
+ }
285
+ ```
286
+
287
+ Hashes are stored in a yaml file with a mapping of Filename => [list of hashes] in config/script_hashes.yml. You can automatically populate this file by running the following rake task:
288
+
289
+ ```$ bundle exec rake secure_headers:generate_hashes```
290
+
291
+ Which will generate something like:
292
+
293
+ ```yaml
294
+ # config/script_hashes.yml
295
+ app/views/layouts/application.html.erb:
296
+ - sha256-l8OLjZqYRnKilpdE0VosRMvhdYArjXT4NZaK2p7QVvs=
297
+ app/templates/articles/edit.html.erb:
298
+ - sha256-+7mij1/uCwtCQRWrof2NmOln5qX+5WdVwTLMpi8nuoA=
299
+ - sha256-Ny4TRIhhFpnYnSeKC274P6bfAz4TOkezLabavIAU4dA=
300
+ - sha256-I5e58Gqbu4WpO9dck18QxO7aYOHKrELIi70it4jIPi0=
301
+ - sha256-Po4LMynwnAJHxiTp3DQaQ3YDBj3paN/xrDoKl4OyxY4=
302
+ ```
303
+
304
+ In this example, if we visit /articles/edit/[id], the above hashes will automatically be added to the CSP header's
305
+ script-src value!
306
+
307
+ You can use plain "script" tags or you can use a built-in helper:
308
+
309
+ ```erb
310
+ <%= hashed_javascript_tag do %>
311
+ console.log("hashed automatically!")
312
+ <% end %>
313
+ ```
314
+
315
+ By using the helper, hash values will be computed dynamically in development/test environments. If a dynamically computed hash value does not match what is expected to be found in config/script_hashes.yml a warning message will be printed to the console. If you want to raise exceptions instead, use:
316
+
317
+ ```erb
318
+ <%= hashed_javascript_tag(raise_error_on_unrecognized_hash = true) do %>
319
+ console.log("will raise an exception if not in script_hashes.yml!")
320
+ <% end %>
321
+ ```
322
+
269
323
  ### Using with Sinatra
270
324
 
271
325
  Here's an example using SecureHeaders for Sinatra applications:
@@ -282,10 +336,10 @@ require 'secure_headers'
282
336
  config.x_content_type_options = "nosniff"
283
337
  config.x_xss_protection = {:value => 1, :mode => false}
284
338
  config.csp = {
285
- :default_src => "https://* inline eval",
339
+ :default_src => "https: inline eval",
286
340
  :report_uri => '//example.com/uri-directive',
287
- :img_src => "https://* data:",
288
- :frame_src => "https://* http://*.twimg.com http://itunes.apple.com"
341
+ :img_src => "https: data:",
342
+ :frame_src => "https: http:.twimg.com http://itunes.apple.com"
289
343
  }
290
344
  end
291
345
 
@@ -337,10 +391,10 @@ def before_load
337
391
  config.x_content_type_options = "nosniff"
338
392
  config.x_xss_protection = {:value => '1', :mode => false}
339
393
  config.csp = {
340
- :default_src => "https://* inline eval",
394
+ :default_src => "https: inline eval",
341
395
  :report_uri => '//example.com/uri-directive',
342
- :img_src => "https://* data:",
343
- :frame_src => "https://* http://*.twimg.com http://itunes.apple.com"
396
+ :img_src => "https: data:",
397
+ :frame_src => "https: http:.twimg.com http://itunes.apple.com"
344
398
  }
345
399
  end
346
400
  end
data/Rakefile CHANGED
@@ -49,119 +49,3 @@ RDoc::Task.new(:rdoc) do |rdoc|
49
49
  rdoc.options << '--line-numbers'
50
50
  rdoc.rdoc_files.include('lib/**/*.rb')
51
51
  end
52
-
53
- UPDATE_URI = 'https://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1'
54
- CA_FILE = File.expand_path(File.join('..', 'config', 'curl-ca-bundle.crt'), __FILE__)
55
- task :fetch_ca_bundle do
56
- begin
57
- FileUtils.cp CA_FILE, CA_FILE + ".bak"
58
- uri = URI.parse(UPDATE_URI)
59
- http = Net::HTTP.new(uri.host, uri.port)
60
- http.use_ssl = true
61
- http.ca_file = CA_FILE
62
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
63
- request = Net::HTTP::Get.new(uri.request_uri)
64
-
65
- ca_file = StringIO.new(http.request(request).body)
66
- File.open(CA_FILE, 'w') do |f|
67
- f.puts mozilla_license
68
- end
69
-
70
- while line = ca_file.gets
71
- next if line =~ /^#/
72
- next if line =~ /^\s*$/
73
- line.chomp!
74
-
75
- if line =~ /CKA_LABEL/
76
- label,type,cert_name = line.split(' ',3)
77
- cert_name.sub!(/^"/, "")
78
- cert_name.sub!(/"$/, "")
79
- next
80
- end
81
- if line =~ /CKA_VALUE MULTILINE_OCTAL/
82
- puts "reading cert for #{cert_name}"
83
- data=''
84
- while line = ca_file.gets
85
- break if line =~ /^END/
86
- line.chomp!
87
- line.gsub(/\\([0-3][0-7][0-7])/) { data += $1.oct.chr }
88
- end
89
-
90
- open(CA_FILE, "a") do |fp|
91
- puts "Appending"
92
- fp.puts cert_name
93
- fp.puts "================"
94
- fp.puts "-----BEGIN CERTIFICATE-----"
95
- fp.puts [data].pack("m*")
96
- fp.puts "-----END CERTIFICATE-----"
97
- fp.puts
98
- end
99
- puts "Parsing: " + cert_name
100
- end
101
- end
102
-
103
- FileUtils.rm CA_FILE + ".bak"
104
- rescue => e
105
- puts "ERRROR #{e}"
106
- puts e.backtrace
107
- FileUtils.mv CA_FILE + '.bak', CA_FILE
108
- end
109
- end
110
-
111
-
112
- def mozilla_license
113
- <<-EOM
114
- ## generated using a modified version of http://curl.haxx.se/mail/lib-2004-07/att-0134/parse-certs.sh
115
- ##
116
- ## lib/ca-bundle.crt -- Bundle of CA Root Certificates
117
- ##
118
- ## Certificate data from Mozilla as of: Tue Mar 27 20:21:58 2012
119
- ##
120
- ## This is a bundle of X.509 certificates of public Certificate Authorities
121
- ## (CA). These were automatically extracted from Mozilla's root certificates
122
- ## file (certdata.txt). This file can be found in the mozilla source tree:
123
- ## http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1
124
- ##
125
- ## It contains the certificates in PEM format and therefore
126
- ## can be directly used with curl / libcurl / php_curl, or with
127
- ## an Apache+mod_ssl webserver for SSL client authentication.
128
- ## Just configure this file as the SSLCACertificateFile.
129
- ##
130
-
131
- # ***** BEGIN LICENSE BLOCK *****
132
- # Version: MPL 1.1/GPL 2.0/LGPL 2.1
133
- #
134
- # The contents of this file are subject to the Mozilla Public License Version
135
- # 1.1 (the "License"); you may not use this file except in compliance with
136
- # the License. You may obtain a copy of the License at
137
- # http://www.mozilla.org/MPL/
138
- #
139
- # Software distributed under the License is distributed on an "AS IS" basis,
140
- # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
141
- # for the specific language governing rights and limitations under the
142
- # License.
143
- #
144
- # The Original Code is the Netscape security libraries.
145
- #
146
- # The Initial Developer of the Original Code is
147
- # Netscape Communications Corporation.
148
- # Portions created by the Initial Developer are Copyright (C) 1994-2000
149
- # the Initial Developer. All Rights Reserved.
150
- #
151
- # Contributor(s):
152
- #
153
- # Alternatively, the contents of this file may be used under the terms of
154
- # either the GNU General Public License Version 2 or later (the "GPL"), or
155
- # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
156
- # in which case the provisions of the GPL or the LGPL are applicable instead
157
- # of those above. If you wish to allow use of your version of this file only
158
- # under the terms of either the GPL or the LGPL, and not to allow others to
159
- # use your version of this file under the terms of the MPL, indicate your
160
- # decision by deleting the provisions above and replace them with the notice
161
- # and other provisions required by the GPL or the LGPL. If you do not delete
162
- # the provisions above, a recipient may use your version of this file under
163
- # the terms of any one of the MPL, the GPL or the LGPL.
164
- #
165
- # ***** END LICENSE BLOCK *****
166
- EOM
167
- end
@@ -3,9 +3,4 @@ source 'https://rubygems.org'
3
3
  gem 'rails', '3.2.12'
4
4
  gem 'rspec-rails', '>= 2.0.0'
5
5
  gem 'secure_headers', :path => '../..'
6
- gem 'debugger', :platform => :ruby_19
7
- gem 'ruby-debug', :platform => :ruby_18
8
- gem 'guard-rspec'
9
- gem 'rb-fsevent'
10
- gem 'growl'
11
6
 
@@ -1,6 +1,5 @@
1
1
  class ThingsController < ApplicationController
2
2
  ensure_security_headers :csp => false
3
3
  def index
4
- ######## : ) <- Marge Simpson?
5
4
  end
6
5
  end
@@ -2,13 +2,10 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Rails3212</title>
5
- <%= stylesheet_link_tag "application", :media => "all" %>
6
- <%= javascript_include_tag "application" %>
7
- <%= csrf_meta_tags %>
8
5
  </head>
9
6
  <body>
10
7
 
11
8
  <%= yield %>
12
-
9
+ <script>console.log("oh hell nah")</script>
13
10
  </body>
14
11
  </html>
@@ -1 +1,2 @@
1
- index
1
+ index
2
+ <script>console.log("oh what")</script>
@@ -1,68 +1,14 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- # Pick the frameworks you want:
4
- # require "active_record/railtie"
5
3
  require "action_controller/railtie"
6
- # require "action_mailer/railtie"
7
- # require "active_resource/railtie"
8
4
  require "sprockets/railtie"
9
- # require "rails/test_unit/railtie"
10
5
 
11
6
  if defined?(Bundler)
12
- # If you precompile assets before deploying to production, use this line
13
7
  Bundler.require(*Rails.groups(:assets => %w(development test)))
14
- # If you want your assets lazily compiled in production, use this line
15
- # Bundler.require(:default, :assets, Rails.env)
16
8
  end
17
9
 
18
10
  module Rails3212
19
11
  class Application < Rails::Application
20
- # Settings in config/environments/* take precedence over those specified here.
21
- # Application configuration should go into files in config/initializers
22
- # -- all .rb files in that directory are automatically loaded.
23
12
 
24
- # Custom directories with classes and modules you want to be autoloadable.
25
- # config.autoload_paths += %W(#{config.root}/extras)
26
-
27
- # Only load the plugins named here, in the order given (default is alphabetical).
28
- # :all can be used as a placeholder for all plugins not explicitly named.
29
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
30
-
31
- # Activate observers that should always be running.
32
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
-
34
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
36
- # config.time_zone = 'Central Time (US & Canada)'
37
-
38
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40
- # config.i18n.default_locale = :de
41
-
42
- # Configure the default encoding used in templates for Ruby 1.9.
43
- config.encoding = "utf-8"
44
-
45
- # Configure sensitive parameters which will be filtered from the log file.
46
- config.filter_parameters += [:password]
47
-
48
- # Enable escaping HTML in JSON.
49
- config.active_support.escape_html_entities_in_json = true
50
-
51
- # Use SQL instead of Active Record's schema dumper when creating the database.
52
- # This is necessary if your schema can't be completely dumped by the schema dumper,
53
- # like if you have constraints or database-specific column types
54
- # config.active_record.schema_format = :sql
55
-
56
- # Enforce whitelist mode for mass assignment.
57
- # This will create an empty whitelist of attributes available for mass-assignment for all models
58
- # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
59
- # parameters by using an attr_accessible or attr_protected declaration.
60
- # config.active_record.whitelist_attributes = true
61
-
62
- # Enable the asset pipeline
63
- config.assets.enabled = true
64
-
65
- # Version of your assets, change this if you want to expire all your assets
66
- config.assets.version = '1.0'
67
13
  end
68
14
  end
@@ -6,9 +6,9 @@
6
6
  csp = {
7
7
  :default_src => "self",
8
8
  :script_src => "self nonce",
9
- :disable_chrome_extension => true,
10
9
  :disable_fill_missing => true,
11
10
  :report_uri => 'somewhere',
11
+ :script_hash_middleware => true,
12
12
  :enforce => false # false means warnings only
13
13
  }
14
14
 
@@ -1,61 +1,4 @@
1
1
  Rails3212::Application.routes.draw do
2
2
  resources :things
3
-
4
-
5
- # The priority is based upon order of creation:
6
- # first created -> highest priority.
7
-
8
- # Sample of regular route:
9
- # match 'products/:id' => 'catalog#view'
10
- # Keep in mind you can assign values other than :controller and :action
11
-
12
- # Sample of named route:
13
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
14
- # This route can be invoked with purchase_url(:id => product.id)
15
-
16
- # Sample resource route (maps HTTP verbs to controller actions automatically):
17
- # resources :products
18
-
19
- # Sample resource route with options:
20
- # resources :products do
21
- # member do
22
- # get 'short'
23
- # post 'toggle'
24
- # end
25
- #
26
- # collection do
27
- # get 'sold'
28
- # end
29
- # end
30
-
31
- # Sample resource route with sub-resources:
32
- # resources :products do
33
- # resources :comments, :sales
34
- # resource :seller
35
- # end
36
-
37
- # Sample resource route with more complex sub-resources
38
- # resources :products do
39
- # resources :comments
40
- # resources :sales do
41
- # get 'recent', :on => :collection
42
- # end
43
- # end
44
-
45
- # Sample resource route within a namespace:
46
- # namespace :admin do
47
- # # Directs /admin/products/* to Admin::ProductsController
48
- # # (app/controllers/admin/products_controller.rb)
49
- # resources :products
50
- # end
51
-
52
- # You can have the root of your site routed with "root"
53
- # just remember to delete public/index.html.
54
- # root :to => 'welcome#index'
55
-
56
- # See how all your routes lay out with "rake routes"
57
-
58
- # This is a legacy wild controller route that's not recommended for RESTful applications.
59
- # Note: This route will make all actions in every controller accessible via GET requests.
60
3
  match ':controller(/:action(/:id))(.:format)'
61
4
  end
@@ -0,0 +1,5 @@
1
+ ---
2
+ app/views/layouts/application.html.erb:
3
+ - sha256-VjDxT7saxd2FgaUQQTWw/jsTnvonaoCP/ACWDBTpyhU=
4
+ app/views/other_things/index.html.erb:
5
+ - sha256-ZXAcP8a0y1pPMTJW8pUr43c+XBkgYQBwHOPvXk9mq5A=
@@ -2,3 +2,6 @@
2
2
 
3
3
  require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Rails3212::Application
5
+
6
+ require 'secure_headers/headers/content_security_policy/script_hash_middleware'
7
+ use ::SecureHeaders::ContentSecurityPolicy::ScriptHashMiddleware