secure_headers 1.1.1 → 1.4.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.
Files changed (80) hide show
  1. data/.ruby-gemset +1 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +2 -3
  4. data/Gemfile +2 -7
  5. data/HISTORY.md +47 -0
  6. data/README.md +74 -27
  7. data/app/controllers/content_security_policy_controller.rb +1 -0
  8. data/fixtures/rails_3_2_12/Gemfile +0 -8
  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 +0 -3
  11. data/fixtures/rails_3_2_12/app/views/things/index.html.erb +1 -21
  12. data/fixtures/rails_3_2_12/config/application.rb +0 -54
  13. data/fixtures/rails_3_2_12/config/environments/test.rb +2 -2
  14. data/fixtures/rails_3_2_12/config/initializers/secure_headers.rb +1 -0
  15. data/fixtures/rails_3_2_12/config/routes.rb +0 -57
  16. data/fixtures/rails_3_2_12/spec/controllers/other_things_controller_spec.rb +15 -14
  17. data/fixtures/rails_3_2_12/spec/controllers/things_controller_spec.rb +12 -12
  18. data/fixtures/rails_3_2_12/spec/spec_helper.rb +1 -5
  19. data/fixtures/rails_3_2_12_no_init/Gemfile +0 -9
  20. data/fixtures/rails_3_2_12_no_init/app/controllers/things_controller.rb +1 -1
  21. data/fixtures/rails_3_2_12_no_init/app/views/layouts/application.html.erb +0 -2
  22. data/fixtures/rails_3_2_12_no_init/app/views/things/index.html.erb +0 -21
  23. data/fixtures/rails_3_2_12_no_init/config/application.rb +0 -51
  24. data/fixtures/rails_3_2_12_no_init/config/environments/test.rb +2 -2
  25. data/fixtures/rails_3_2_12_no_init/config/routes.rb +0 -57
  26. data/fixtures/rails_3_2_12_no_init/spec/controllers/other_things_controller_spec.rb +12 -12
  27. data/fixtures/rails_3_2_12_no_init/spec/controllers/things_controller_spec.rb +12 -12
  28. data/fixtures/rails_3_2_12_no_init/spec/spec_helper.rb +3 -18
  29. data/lib/secure_headers/headers/content_security_policy.rb +54 -35
  30. data/lib/secure_headers/headers/strict_transport_security.rb +2 -1
  31. data/lib/secure_headers/headers/x_download_options.rb +39 -0
  32. data/lib/secure_headers/headers/x_xss_protection.rb +2 -1
  33. data/lib/secure_headers/padrino.rb +14 -0
  34. data/lib/secure_headers/railtie.rb +6 -2
  35. data/lib/secure_headers/version.rb +1 -1
  36. data/lib/secure_headers.rb +9 -2
  37. data/spec/controllers/content_security_policy_controller_spec.rb +19 -19
  38. data/spec/lib/secure_headers/headers/content_security_policy_spec.rb +117 -85
  39. data/spec/lib/secure_headers/headers/strict_transport_security_spec.rb +21 -20
  40. data/spec/lib/secure_headers/headers/x_content_type_options_spec.rb +12 -12
  41. data/spec/lib/secure_headers/headers/x_download_options_spec.rb +32 -0
  42. data/spec/lib/secure_headers/headers/x_frame_options_spec.rb +12 -12
  43. data/spec/lib/secure_headers/headers/x_xss_protection_spec.rb +20 -19
  44. data/spec/lib/secure_headers_spec.rb +38 -12
  45. data/spec/spec_helper.rb +10 -24
  46. metadata +9 -37
  47. data/.rvmrc +0 -1
  48. data/Guardfile +0 -10
  49. data/fixtures/rails_3_2_12/Guardfile +0 -14
  50. data/fixtures/rails_3_2_12/app/models/thing.rb +0 -3
  51. data/fixtures/rails_3_2_12/config/database.yml +0 -25
  52. data/fixtures/rails_3_2_12/config/environments/development.rb +0 -37
  53. data/fixtures/rails_3_2_12/config/environments/production.rb +0 -67
  54. data/fixtures/rails_3_2_12/config/initializers/backtrace_silencers.rb +0 -7
  55. data/fixtures/rails_3_2_12/config/initializers/inflections.rb +0 -15
  56. data/fixtures/rails_3_2_12/config/initializers/mime_types.rb +0 -5
  57. data/fixtures/rails_3_2_12/config/initializers/secret_token.rb +0 -7
  58. data/fixtures/rails_3_2_12/config/initializers/session_store.rb +0 -8
  59. data/fixtures/rails_3_2_12/config/initializers/wrap_parameters.rb +0 -14
  60. data/fixtures/rails_3_2_12/config/locales/en.yml +0 -5
  61. data/fixtures/rails_3_2_12/db/schema.rb +0 -16
  62. data/fixtures/rails_3_2_12/db/seeds.rb +0 -7
  63. data/fixtures/rails_3_2_12_no_init/Guardfile +0 -14
  64. data/fixtures/rails_3_2_12_no_init/app/models/thing.rb +0 -3
  65. data/fixtures/rails_3_2_12_no_init/app/views/things/_form.html.erb +0 -17
  66. data/fixtures/rails_3_2_12_no_init/app/views/things/edit.html.erb +0 -6
  67. data/fixtures/rails_3_2_12_no_init/app/views/things/new.html.erb +0 -5
  68. data/fixtures/rails_3_2_12_no_init/app/views/things/show.html.erb +0 -5
  69. data/fixtures/rails_3_2_12_no_init/config/database.yml +0 -25
  70. data/fixtures/rails_3_2_12_no_init/config/environments/development.rb +0 -37
  71. data/fixtures/rails_3_2_12_no_init/config/environments/production.rb +0 -67
  72. data/fixtures/rails_3_2_12_no_init/config/initializers/backtrace_silencers.rb +0 -7
  73. data/fixtures/rails_3_2_12_no_init/config/initializers/inflections.rb +0 -15
  74. data/fixtures/rails_3_2_12_no_init/config/initializers/mime_types.rb +0 -5
  75. data/fixtures/rails_3_2_12_no_init/config/initializers/secret_token.rb +0 -7
  76. data/fixtures/rails_3_2_12_no_init/config/initializers/session_store.rb +0 -8
  77. data/fixtures/rails_3_2_12_no_init/config/initializers/wrap_parameters.rb +0 -14
  78. data/fixtures/rails_3_2_12_no_init/config/locales/en.yml +0 -5
  79. data/fixtures/rails_3_2_12_no_init/db/schema.rb +0 -16
  80. data/fixtures/rails_3_2_12_no_init/db/seeds.rb +0 -7
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ secureheaders
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p484
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  rvm:
2
+ - "2.1.0"
3
+ - "2.0.0"
2
4
  - "1.9.3"
3
5
  - "1.8.7"
4
- # - jruby-19mode
5
- # - jruby-18mode
6
- #script: ./travis.sh
data/Gemfile CHANGED
@@ -6,15 +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 'spork'
11
- gem 'pry'
12
- gem 'rspec'
13
- gem 'guard-spork', :platform => :ruby_19
14
- gem 'guard-rspec', :platform => :ruby_19
9
+ gem 'rspec-rails', '>= 3.1'
10
+ gem 'rspec', '>= 3.1'
15
11
  gem 'growl'
16
12
  gem 'rb-fsevent'
17
- gem 'simplecov'
18
13
  gem 'debugger', :platform => :ruby_19
19
14
  gem 'ruby-debug', :platform => :ruby_18
20
15
  end
data/HISTORY.md CHANGED
@@ -1,3 +1,50 @@
1
+ 1.3.4
2
+ ======
3
+
4
+ * Adds X-Download-Options support
5
+ * Adds support for X-XSS-Protection reporting
6
+ * Defers loading of rails engine for faster boot times
7
+
8
+ 1.3.3
9
+ ======
10
+
11
+ @agl just made a new option for HSTS representing confirmation that a site wants to be included in a browser's preload list (https://hstspreload.appspot.com).
12
+
13
+ This just adds a new 'preload' option to the HSTS settings to specify that option.
14
+
15
+ 1.3.2
16
+ ======
17
+
18
+ Adds the ability to "tag" requests and a new config value: :app_name
19
+
20
+ {
21
+ :tag_report_uri => true,
22
+ :enforce => true,
23
+ :app_name => 'twitter',
24
+ :report_uri => 'csp_reports'
25
+ }
26
+
27
+ Results in
28
+ report-uri csp_reports?enforce=true&app_name=twitter
29
+
30
+
31
+ 1.3.1
32
+ ======
33
+
34
+ Bugfix release: same-origin detection would error out when the URL containined invalid values (like |)
35
+
36
+ 1.3.0
37
+ ======
38
+
39
+ - CSP nonce support was added back and is compliant.
40
+ - Bugs:
41
+ -- enforce, disable_fill_missing, and disable_chrome_extension did not accept lambdas for no good reason
42
+ -- IF a default-src was specified, and an img-src was not, and disable_fill_missing was true, the img-src value would be :data
43
+
44
+ 1.2.0
45
+ ======
46
+ - Allow procs to be used as config values.
47
+
1
48
  1.1.1
2
49
  ======
3
50
 
data/README.md CHANGED
@@ -85,9 +85,10 @@ Or simply add it to application controller
85
85
 
86
86
  ```ruby
87
87
  ensure_security_headers(
88
- :hsts => {:include_subdomains, :x_frame_options => false},
88
+ :hsts => {:include_subdomains => true, :max_age => 20.years.to_i},
89
89
  :x_frame_options => 'DENY',
90
- :csp => false)
90
+ :csp => false
91
+ )
91
92
  ```
92
93
 
93
94
  ## Options for ensure\_security\_headers
@@ -162,13 +163,6 @@ and [Mozilla CSP specification](https://wiki.mozilla.org/Security/CSP/Specificat
162
163
  :img_src => 'http://mycdn.example.com'
163
164
  }
164
165
  }
165
-
166
- # script-nonce is an experimental feature of CSP 1.1 available in Chrome. It allows
167
- # you to whitelist inline script blocks. For more information, see
168
- # https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-nonce
169
- :script_nonce => lambda { @script_nonce = SecureRandom.hex }
170
- # which can be used to whitelist a script block:
171
- # script_tag :nonce = @script_nonce { inline_script_call() }
172
166
  }
173
167
  ```
174
168
 
@@ -203,9 +197,54 @@ and [Mozilla CSP specification](https://wiki.mozilla.org/Security/CSP/Specificat
203
197
  "default-src 'self'; img-src *; object-src media1.com media2.com *.cdn.com; script-src trustedscripts.example.com;"
204
198
  ```
205
199
 
206
- ## Note on Firefox handling of CSP
200
+ ### Tagging Requests
201
+
202
+ It's often valuable to send extra information in the report uri that is not available in the reports themselves. Namely, "was the policy enforced" and "where did the report come from"
203
+
204
+ ```ruby
205
+ {
206
+ :tag_report_uri => true,
207
+ :enforce => true,
208
+ :app_name => 'twitter',
209
+ :report_uri => 'csp_reports'
210
+ }
211
+ ```
212
+
213
+ Results in
214
+ ```
215
+ report-uri csp_reports?enforce=true&app_name=twitter
216
+ ```
217
+
218
+ ### CSP Level 2 features
219
+
220
+ 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
+
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.
223
+
224
+ ```ruby
225
+ :csp => {
226
+ :default_src => 'self',
227
+ :script_src => 'self nonce'
228
+ }
229
+ ```
230
+
231
+ > content-security-policy: default-src 'self'; script-src 'self' 'nonce-abc123' 'unsafe-inline'
207
232
 
208
- Currently, Firefox does not support the w3c draft standard. So there are a few steps taken to make the two interchangeable.
233
+ ```erb
234
+ <script nonce="<%= @content_security_policy_nonce %>">
235
+ console.log("whitelisted, will execute")
236
+ </script>
237
+
238
+ <script nonce="lol">
239
+ console.log("won't execute, not whitelisted")
240
+ </script>
241
+
242
+ <script>
243
+ console.log("won't execute, not whitelisted")
244
+ </script>
245
+ ```
246
+
247
+ ## Note on Firefox handling of CSP
209
248
 
210
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`
211
250
 
@@ -274,22 +313,11 @@ In your `Gemfile`:
274
313
  then in your `app.rb` file you can:
275
314
 
276
315
  ```ruby
316
+ require 'secure_headers/padrino'
317
+
277
318
  module Web
278
319
  class App < Padrino::Application
279
- include SecureHeaders
280
-
281
- ::SecureHeaders::Configuration.configure do |config|
282
- config.hsts = {:max_age => 99, :include_subdomains => true}
283
- config.x_frame_options = 'DENY'
284
- config.x_content_type_options = "nosniff"
285
- config.x_xss_protection = {:value => '1', :mode => false}
286
- config.csp = {
287
- :default_src => "https://* inline eval",
288
- :report_uri => '//example.com/uri-directive',
289
- :img_src => "https://* data:",
290
- :frame_src => "https://* http://*.twimg.com http://itunes.apple.com"
291
- }
292
- end
320
+ register SecureHeaders::Padrino
293
321
 
294
322
  get '/' do
295
323
  set_csp_header
@@ -299,12 +327,31 @@ module Web
299
327
  end
300
328
  ```
301
329
 
330
+ and in `config/boot.rb`:
331
+
332
+ ```ruby
333
+ def before_load
334
+ ::SecureHeaders::Configuration.configure do |config|
335
+ config.hsts = {:max_age => 99, :include_subdomains => true}
336
+ config.x_frame_options = 'DENY'
337
+ config.x_content_type_options = "nosniff"
338
+ config.x_xss_protection = {:value => '1', :mode => false}
339
+ config.csp = {
340
+ :default_src => "https://* inline eval",
341
+ :report_uri => '//example.com/uri-directive',
342
+ :img_src => "https://* data:",
343
+ :frame_src => "https://* http://*.twimg.com http://itunes.apple.com"
344
+ }
345
+ end
346
+ end
347
+ ```
348
+
302
349
  ## Similar libraries
303
350
 
304
351
  * Node.js (express) [helmet](https://github.com/evilpacket/helmet) and [hood](https://github.com/seanmonstar/hood)
305
352
  * J2EE Servlet >= 3.0 [highlines](https://github.com/sourceclear/headlines)
306
353
  * ASP.NET - [NWebsec](http://nwebsec.codeplex.com/)
307
- * Python - [django-csp](https://github.com/mozilla/django-csp/tree/master/csp) + [commonware](https://github.com/jsocol/commonware/tree/master/commonware/request)
354
+ * Python - [django-csp](https://github.com/mozilla/django-csp/) + [commonware](https://github.com/jsocol/commonware/)
308
355
  * Go - [secureheader](https://github.com/kr/secureheader)
309
356
 
310
357
  ## Authors
@@ -321,6 +368,6 @@ end
321
368
 
322
369
  ## License
323
370
 
324
- Copyright 2013 Twitter, Inc.
371
+ Copyright 2013-2014 Twitter, Inc and other contributors.
325
372
 
326
373
  Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
@@ -5,6 +5,7 @@ class ContentSecurityPolicyController < ActionController::Base
5
5
  CA_FILE = File.expand_path(File.join('..','..', '..', 'config', 'curl-ca-bundle.crt'), __FILE__)
6
6
 
7
7
  def scribe
8
+ warn "[DEPRECATION] ContentSecurityPolicyController is removed in 2.0"
8
9
  csp = ::SecureHeaders::Configuration.csp || {}
9
10
 
10
11
  forward_endpoint = csp[:forward_endpoint]
@@ -1,14 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.2.12'
4
- gem 'sqlite3'
5
4
  gem 'rspec-rails', '>= 2.0.0'
6
5
  gem 'secure_headers', :path => '../..'
7
- gem 'spork'
8
- gem 'debugger', :platform => :ruby_19
9
- gem 'ruby-debug', :platform => :ruby_18
10
- gem 'guard-rspec'
11
- gem 'guard-spork'
12
- gem 'rb-fsevent'
13
- gem 'growl'
14
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,9 +2,6 @@
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
 
@@ -1,21 +1 @@
1
- <h1>Listing things</h1>
2
-
3
- <table>
4
- <tr>
5
- <th></th>
6
- <th></th>
7
- <th></th>
8
- </tr>
9
-
10
- <% @things.each do |thing| %>
11
- <tr>
12
- <td><%= link_to 'Show', thing %></td>
13
- <td><%= link_to 'Edit', edit_thing_path(thing) %></td>
14
- <td><%= link_to 'Destroy', thing, method: :delete, data: { confirm: 'Are you sure?' } %></td>
15
- </tr>
16
- <% end %>
17
- </table>
18
-
19
- <br />
20
-
21
- <%= link_to 'New Thing', new_thing_path %>
1
+ things
@@ -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
@@ -27,10 +27,10 @@ Rails3212::Application.configure do
27
27
  # Tell Action Mailer not to deliver emails to the real world.
28
28
  # The :test delivery method accumulates sent emails in the
29
29
  # ActionMailer::Base.deliveries array.
30
- config.action_mailer.delivery_method = :test
30
+ # config.action_mailer.delivery_method = :test
31
31
 
32
32
  # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
33
+ # config.active_record.mass_assignment_sanitizer = :strict
34
34
 
35
35
  # Print deprecation notices to the stderr
36
36
  config.active_support.deprecation = :stderr
@@ -5,6 +5,7 @@
5
5
  config.x_xss_protection = {:value => 1, :mode => 'block'}
6
6
  csp = {
7
7
  :default_src => "self",
8
+ :script_src => "self nonce",
8
9
  :disable_chrome_extension => true,
9
10
  :disable_fill_missing => true,
10
11
  :report_uri => 'somewhere',
@@ -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
@@ -1,44 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe OtherThingsController do
3
+ describe OtherThingsController, :type => :controller do
4
4
  describe "headers" do
5
- before(:each) do
6
- # Chrome
7
- request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5'
8
- end
9
-
10
5
  it "sets the X-XSS-Protection header" do
11
6
  get :index
12
- response.headers['X-XSS-Protection'].should == '1; mode=block'
7
+ expect(response.headers['X-XSS-Protection']).to eq('1; mode=block')
13
8
  end
14
9
 
15
10
  it "sets the X-Frame-Options header" do
16
11
  get :index
17
- response.headers['X-Frame-Options'].should == 'SAMEORIGIN'
12
+ expect(response.headers['X-Frame-Options']).to eq('SAMEORIGIN')
18
13
  end
19
14
 
20
- it "sets the X-WebKit-CSP header" do
15
+ it "sets the CSP header with a local reference to a nonce" do
21
16
  get :index
22
- response.headers['Content-Security-Policy-Report-Only'].should == "default-src 'self'; img-src data:; report-uri somewhere;"
17
+ nonce = controller.instance_exec { @content_security_policy_nonce }
18
+ expect(nonce).to match /[a-zA-Z0-9\+\/=]{44}/
19
+ expect(response.headers['Content-Security-Policy-Report-Only']).to match(/default-src 'self'; img-src 'self' data:; script-src 'self' 'nonce-[a-zA-Z0-9\+\/=]{44}' 'unsafe-inline'; report-uri somewhere;/)
23
20
  end
24
21
 
25
- #mock ssl
26
22
  it "sets the Strict-Transport-Security header" do
27
23
  request.env['HTTPS'] = 'on'
28
24
  get :index
29
- response.headers['Strict-Transport-Security'].should == "max-age=315576000"
25
+ expect(response.headers['Strict-Transport-Security']).to eq("max-age=315576000")
26
+ end
27
+
28
+ it "sets the X-Download-Options header" do
29
+ get :index
30
+ expect(response.headers['X-Download-Options']).to eq('noopen')
30
31
  end
31
32
 
32
33
  it "sets the X-Content-Type-Options header" do
33
34
  get :index
34
- response.headers['X-Content-Type-Options'].should == "nosniff"
35
+ expect(response.headers['X-Content-Type-Options']).to eq("nosniff")
35
36
  end
36
37
 
37
38
  context "using IE" do
38
39
  it "sets the X-Content-Type-Options header" do
39
40
  request.env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
40
41
  get :index
41
- response.headers['X-Content-Type-Options'].should == "nosniff"
42
+ expect(response.headers['X-Content-Type-Options']).to eq("nosniff")
42
43
  end
43
44
  end
44
45
  end
@@ -4,45 +4,45 @@ require 'spec_helper'
4
4
  # all values are defaulted because no initializer is configured, and the values in app controller
5
5
  # only provide csp => false
6
6
 
7
- describe ThingsController do
7
+ describe ThingsController, :type => :controller do
8
8
  describe "headers" do
9
- before(:each) do
10
- # Chrome
11
- request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5'
12
- end
13
-
14
9
  it "sets the X-XSS-Protection header" do
15
10
  get :index
16
- response.headers['X-XSS-Protection'].should == '1; mode=block'
11
+ expect(response.headers['X-XSS-Protection']).to eq('1; mode=block')
17
12
  end
18
13
 
19
14
  it "sets the X-Frame-Options header" do
20
15
  get :index
21
- response.headers['X-Frame-Options'].should == 'SAMEORIGIN'
16
+ expect(response.headers['X-Frame-Options']).to eq('SAMEORIGIN')
22
17
  end
23
18
 
24
19
  it "sets the X-WebKit-CSP header" do
25
20
  get :index
26
- response.headers['Content-Security-Policy-Report-Only'].should == nil
21
+ expect(response.headers['Content-Security-Policy-Report-Only']).to eq(nil)
27
22
  end
28
23
 
29
24
  #mock ssl
30
25
  it "sets the Strict-Transport-Security header" do
31
26
  request.env['HTTPS'] = 'on'
32
27
  get :index
33
- response.headers['Strict-Transport-Security'].should == "max-age=315576000"
28
+ expect(response.headers['Strict-Transport-Security']).to eq("max-age=315576000")
29
+ end
30
+
31
+ it "sets the X-Download-Options header" do
32
+ get :index
33
+ expect(response.headers['X-Download-Options']).to eq('noopen')
34
34
  end
35
35
 
36
36
  it "sets the X-Content-Type-Options header" do
37
37
  get :index
38
- response.headers['X-Content-Type-Options'].should == "nosniff"
38
+ expect(response.headers['X-Content-Type-Options']).to eq("nosniff")
39
39
  end
40
40
 
41
41
  context "using IE" do
42
42
  it "sets the X-Content-Type-Options header" do
43
43
  request.env['HTTP_USER_AGENT'] = "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
44
44
  get :index
45
- response.headers['X-Content-Type-Options'].should == "nosniff"
45
+ expect(response.headers['X-Content-Type-Options']).to eq("nosniff")
46
46
  end
47
47
  end
48
48
  end
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'spork'
2
+
3
3
  #uncomment the following line to use spork with the debugger
4
4
  #require 'spork/ext/ruby-debug'
5
5
 
@@ -11,9 +11,5 @@ require 'spork'
11
11
  ENV["RAILS_ENV"] ||= 'test'
12
12
  require File.expand_path("../../config/environment", __FILE__)
13
13
  require 'rspec/rails'
14
- require 'rspec/autorun'
15
14
  # end
16
15
 
17
- Spork.each_run do
18
-
19
- end
@@ -1,14 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails', '3.2.12'
4
- gem 'sqlite3'
5
4
  gem 'rspec-rails', '>= 2.0.0'
6
5
  gem 'secure_headers', :path => '../..'
7
- gem 'spork'
8
- gem 'debugger', :platform => :ruby_19
9
- gem 'ruby-debug', :platform => :ruby_18
10
- gem 'guard-rspec'
11
- gem 'guard-spork'
12
- gem 'rb-fsevent'
13
- gem 'growl'
14
-
@@ -1,5 +1,5 @@
1
1
  class ThingsController < ApplicationController
2
2
  def index
3
- ######## : ) <- Marge Simpson?
3
+
4
4
  end
5
5
  end
@@ -3,8 +3,6 @@
3
3
  <head>
4
4
  <title>Rails3212</title>
5
5
  <%= stylesheet_link_tag "application", :media => "all" %>
6
- <%= javascript_include_tag "application" %>
7
- <%= csrf_meta_tags %>
8
6
  </head>
9
7
  <body>
10
8
 
@@ -1,21 +0,0 @@
1
- <h1>Listing things</h1>
2
-
3
- <table>
4
- <tr>
5
- <th></th>
6
- <th></th>
7
- <th></th>
8
- </tr>
9
-
10
- <% @things.each do |thing| %>
11
- <tr>
12
- <td><%= link_to 'Show', thing %></td>
13
- <td><%= link_to 'Edit', edit_thing_path(thing) %></td>
14
- <td><%= link_to 'Destroy', thing, method: :delete, data: { confirm: 'Are you sure?' } %></td>
15
- </tr>
16
- <% end %>
17
- </table>
18
-
19
- <br />
20
-
21
- <%= link_to 'New Thing', new_thing_path %>