secure_headers 1.4.1 → 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of secure_headers might be problematic. Click here for more details.

Files changed (32) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -8
  3. data/Gemfile +2 -2
  4. data/Guardfile +8 -0
  5. data/README.md +102 -48
  6. data/Rakefile +0 -116
  7. data/fixtures/rails_3_2_12/app/views/layouts/application.html.erb +1 -1
  8. data/fixtures/rails_3_2_12/app/views/other_things/index.html.erb +2 -1
  9. data/fixtures/rails_3_2_12/config/initializers/secure_headers.rb +1 -1
  10. data/fixtures/rails_3_2_12/config/script_hashes.yml +5 -0
  11. data/fixtures/rails_3_2_12/config.ru +3 -0
  12. data/fixtures/rails_3_2_12/spec/controllers/other_things_controller_spec.rb +50 -18
  13. data/fixtures/rails_3_2_12/spec/controllers/things_controller_spec.rb +1 -1
  14. data/fixtures/rails_3_2_12_no_init/app/controllers/other_things_controller.rb +1 -2
  15. data/lib/secure_headers/hash_helper.rb +7 -0
  16. data/lib/secure_headers/headers/content_security_policy/script_hash_middleware.rb +22 -0
  17. data/lib/secure_headers/headers/content_security_policy.rb +141 -137
  18. data/lib/secure_headers/railtie.rb +0 -22
  19. data/lib/secure_headers/version.rb +1 -1
  20. data/lib/secure_headers/view_helper.rb +68 -0
  21. data/lib/secure_headers.rb +51 -17
  22. data/lib/tasks/tasks.rake +48 -0
  23. data/spec/lib/secure_headers/headers/content_security_policy/script_hash_middleware_spec.rb +47 -0
  24. data/spec/lib/secure_headers/headers/content_security_policy_spec.rb +83 -208
  25. data/spec/lib/secure_headers_spec.rb +16 -62
  26. data/spec/spec_helper.rb +25 -1
  27. metadata +22 -24
  28. data/HISTORY.md +0 -162
  29. data/app/controllers/content_security_policy_controller.rb +0 -76
  30. data/config/curl-ca-bundle.crt +0 -5420
  31. data/config/routes.rb +0 -3
  32. data/spec/controllers/content_security_policy_controller_spec.rb +0 -90
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secure_headers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
5
- prerelease:
4
+ version: 2.0.0.pre
6
5
  platform: ruby
7
6
  authors:
8
7
  - Neil Matatall
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-11-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: Add easily configured browser headers to responses.
@@ -34,18 +31,15 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
38
- - .ruby-gemset
39
- - .ruby-version
40
- - .travis.yml
34
+ - ".gitignore"
35
+ - ".ruby-gemset"
36
+ - ".ruby-version"
37
+ - ".travis.yml"
41
38
  - Gemfile
42
- - HISTORY.md
39
+ - Guardfile
43
40
  - LICENSE
44
41
  - README.md
45
42
  - Rakefile
46
- - app/controllers/content_security_policy_controller.rb
47
- - config/curl-ca-bundle.crt
48
- - config/routes.rb
49
43
  - fixtures/rails_3_2_12/.rspec
50
44
  - fixtures/rails_3_2_12/Gemfile
51
45
  - fixtures/rails_3_2_12/README.rdoc
@@ -64,6 +58,7 @@ files:
64
58
  - fixtures/rails_3_2_12/config/environments/test.rb
65
59
  - fixtures/rails_3_2_12/config/initializers/secure_headers.rb
66
60
  - fixtures/rails_3_2_12/config/routes.rb
61
+ - fixtures/rails_3_2_12/config/script_hashes.yml
67
62
  - fixtures/rails_3_2_12/lib/assets/.gitkeep
68
63
  - fixtures/rails_3_2_12/lib/tasks/.gitkeep
69
64
  - fixtures/rails_3_2_12/log/.gitkeep
@@ -100,8 +95,10 @@ files:
100
95
  - fixtures/rails_3_2_12_no_init/vendor/assets/stylesheets/.gitkeep
101
96
  - fixtures/rails_3_2_12_no_init/vendor/plugins/.gitkeep
102
97
  - lib/secure_headers.rb
98
+ - lib/secure_headers/hash_helper.rb
103
99
  - lib/secure_headers/header.rb
104
100
  - lib/secure_headers/headers/content_security_policy.rb
101
+ - lib/secure_headers/headers/content_security_policy/script_hash_middleware.rb
105
102
  - lib/secure_headers/headers/strict_transport_security.rb
106
103
  - lib/secure_headers/headers/x_content_type_options.rb
107
104
  - lib/secure_headers/headers/x_download_options.rb
@@ -110,8 +107,10 @@ files:
110
107
  - lib/secure_headers/padrino.rb
111
108
  - lib/secure_headers/railtie.rb
112
109
  - lib/secure_headers/version.rb
110
+ - lib/secure_headers/view_helper.rb
111
+ - lib/tasks/tasks.rake
113
112
  - secure_headers.gemspec
114
- - spec/controllers/content_security_policy_controller_spec.rb
113
+ - spec/lib/secure_headers/headers/content_security_policy/script_hash_middleware_spec.rb
115
114
  - spec/lib/secure_headers/headers/content_security_policy_spec.rb
116
115
  - spec/lib/secure_headers/headers/strict_transport_security_spec.rb
117
116
  - spec/lib/secure_headers/headers/x_content_type_options_spec.rb
@@ -124,31 +123,30 @@ files:
124
123
  homepage: https://github.com/twitter/secureheaders
125
124
  licenses:
126
125
  - Apache Public License 2.0
126
+ metadata: {}
127
127
  post_install_message:
128
128
  rdoc_options: []
129
129
  require_paths:
130
130
  - lib
131
131
  required_ruby_version: !ruby/object:Gem::Requirement
132
- none: false
133
132
  requirements:
134
- - - ! '>='
133
+ - - ">="
135
134
  - !ruby/object:Gem::Version
136
135
  version: '0'
137
136
  required_rubygems_version: !ruby/object:Gem::Requirement
138
- none: false
139
137
  requirements:
140
- - - ! '>='
138
+ - - ">"
141
139
  - !ruby/object:Gem::Version
142
- version: '0'
140
+ version: 1.3.1
143
141
  requirements: []
144
142
  rubyforge_project:
145
- rubygems_version: 1.8.23
143
+ rubygems_version: 2.2.2
146
144
  signing_key:
147
- specification_version: 3
145
+ specification_version: 4
148
146
  summary: Add easily configured browser headers to responses including content security
149
147
  policy, x-frame-options, strict-transport-security and more.
150
148
  test_files:
151
- - spec/controllers/content_security_policy_controller_spec.rb
149
+ - spec/lib/secure_headers/headers/content_security_policy/script_hash_middleware_spec.rb
152
150
  - spec/lib/secure_headers/headers/content_security_policy_spec.rb
153
151
  - spec/lib/secure_headers/headers/strict_transport_security_spec.rb
154
152
  - spec/lib/secure_headers/headers/x_content_type_options_spec.rb
data/HISTORY.md DELETED
@@ -1,162 +0,0 @@
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
-
48
- 1.1.1
49
- ======
50
-
51
- Bug fix release.
52
- - Parsing of CSP reports was busted.
53
- - Forwarded reports did not include the original referer, ip, UA
54
-
55
- 1.1.0
56
- ======
57
-
58
- - Remove brwsr dependency (no more runtime dependencies)
59
- - Stop serving X- prefixed CSP headers
60
-
61
- This change means that all requests get all headers, even if the browser doesn't grok it.
62
-
63
- 1.0.0
64
- ======
65
-
66
- Features:
67
-
68
- - Use non-prefixed header names for Firefox >= 23, Chrome >= 25
69
- - Use csp 1.0 compliant header for firefox >= 23
70
-
71
- Bug Fix:
72
-
73
- - Stop sending CSP on safari 5.1+
74
-
75
- 0.5.0
76
- ======
77
-
78
- - X-Content-Type-Options also applied to Chrome requests
79
-
80
- 0.4.3
81
- ======
82
-
83
- - Safari 5 is just completely broken when CSP is used, both mobile and desktop versions
84
-
85
- 0.4.2
86
- ======
87
-
88
- - Stupid bug where Fixnums couldn't be used for config values
89
- - Doc updates
90
-
91
- 0.4.1
92
- ======
93
-
94
- - Allow strings or ints in the HSTS max-age (@reedloden)
95
-
96
- 0.4.0
97
- =======
98
-
99
- - Treat each header as it's own before_filter. This allows you to `skip_before_filter :set_X_header, :only => :bad_idea
100
- - Should be backwards compatible, but it is a change to the API.
101
-
102
- 0.3.0
103
- =======
104
-
105
- - Greatly reduce the need to use the forward_endpoint attribute. If you are posting from your site to a host that matches TLD+1 (e.g. translate.twitter.com matches twitter.com), use a protocol relative value for report-uri. This will alleviate the need to use forwarding. If your host doesn't match, you still need to use forwarding due to host mismatches for Firefox.
106
-
107
- 0.2.3
108
- =======
109
-
110
- - Fix error in report-uri logic for Firefox forwarding.
111
-
112
- 0.2.2
113
- =======
114
-
115
- - Stop applying chrome-extension: to Firefox directives.
116
-
117
- 0.2.1
118
- =======
119
-
120
- - Firefox headers will now stop overriding report_uri when only a path is supplied
121
-
122
- 0.2.0
123
- =======
124
-
125
- - 0.1.0 introduced a serious regression in which child controllers overwrote parent controller config values
126
- - Decoupling of CSP headers and the request object. Allows you to generate static values to save cycles:
127
-
128
- ```ruby
129
- FIREFOX = SecureHeaders::ContentSecurityPolicy.new(config, :ua => "Firefox", :ssl => true).value
130
- CHROME = SecureHeaders::ContentSecurityPolicy.new(config, :ua => "Chrome", :ssl => true).value
131
- ```
132
- - :forward_endpoint now acts as the endpoint that reports are forwarded to (when using the internal forwarder feature for cross-host reporting)
133
- - Skeleton applications have been added to test isolated application configurations
134
- - Cleanup by @bemurphy
135
-
136
- 0.1.1
137
- =======
138
-
139
- Bug fix. Firefox doesn't seem to like the default-src directive, reverting back to 'allow'
140
-
141
- 0.1.0
142
- =======
143
-
144
- Notes:
145
- ------
146
-
147
- - Gem is renamed to secure_headers. This will make bundler happy. https://github.com/twitter/secureheaders/pull/26
148
-
149
- Features:
150
- ------
151
-
152
- - ability to apply two headers, one in enforce mode, one in "experimental" mode https://github.com/twitter/secureheaders/pull/11
153
- - Rails 3.0 support https://github.com/twitter/secureheaders/pull/28
154
-
155
- Bug fixes, misc:
156
- ------
157
-
158
- - Fix issue where settings in application_controller were ignored if no intializer was supplied https://github.com/twitter/secureheaders/pull/25
159
- - Better support for other frameworks, including docs from @achui, @bmaland
160
- - Rails 4 routes support from @jviney https://github.com/twitter/secureheaders/pull/13
161
- - data: automatically whitelisted for img-src
162
- - Doc updates from @ming13, @theverything, @dcollazo
@@ -1,76 +0,0 @@
1
- require 'net/https'
2
- require 'openssl'
3
-
4
- class ContentSecurityPolicyController < ActionController::Base
5
- CA_FILE = File.expand_path(File.join('..','..', '..', 'config', 'curl-ca-bundle.crt'), __FILE__)
6
-
7
- def scribe
8
- warn "[DEPRECATION] ContentSecurityPolicyController is removed in 2.0"
9
- csp = ::SecureHeaders::Configuration.csp || {}
10
-
11
- forward_endpoint = csp[:forward_endpoint]
12
- if forward_endpoint
13
- forward_params_to(forward_endpoint)
14
- end
15
-
16
- head :ok
17
- rescue StandardError => e
18
- log_warning(forward_endpoint, e)
19
- head :bad_request
20
- end
21
-
22
- private
23
-
24
- def forward_params_to(forward_endpoint)
25
- uri = URI.parse(forward_endpoint)
26
- http = Net::HTTP.new(uri.host, uri.port)
27
- if uri.scheme == 'https'
28
- use_ssl(http)
29
- end
30
-
31
- if request.content_type == "application/csp-report"
32
- request.body.rewind
33
- params.merge!(ActiveSupport::JSON.decode(request.body.read))
34
- end
35
-
36
- ua = request.user_agent
37
- xff = forwarded_for
38
-
39
- request = Net::HTTP::Post.new(uri.to_s)
40
- request.initialize_http_header({
41
- 'User-Agent' => ua,
42
- 'X-Forwarded-For' => xff,
43
- 'Content-Type' => 'application/json',
44
- })
45
- request.body = params.to_json
46
-
47
- # fire and forget
48
- if defined?(Delayed::Job)
49
- http.delay.request(request)
50
- else
51
- http.request(request)
52
- end
53
- end
54
-
55
- def forwarded_for
56
- req_xff = request.env["HTTP_X_FORWARDED_FOR"]
57
- if req_xff && req_xff != ""
58
- "#{req_xff}, #{request.remote_ip}"
59
- else
60
- request.remote_ip
61
- end
62
- end
63
-
64
- def use_ssl request
65
- request.use_ssl = true
66
- request.ca_file = CA_FILE
67
- request.verify_mode = OpenSSL::SSL::VERIFY_PEER
68
- request.verify_depth = 9
69
- end
70
-
71
- def log_warning(forward_endpoint, e)
72
- if defined?(Rails.logger)
73
- Rails.logger.warn("Unable to POST CSP report to #{forward_endpoint} because #{e}")
74
- end
75
- end
76
- end