rack-secure_headers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7136f261dc9b340a0d89d3c10f8737718aecb64
4
- data.tar.gz: 0efdaba9b544e47ee5d8b774caa9e00cadf8e5c1
3
+ metadata.gz: e495954722a9dfbac925e93f2e31364056083f04
4
+ data.tar.gz: 433960cb3b6821c8326d70ee356c452b57748345
5
5
  SHA512:
6
- metadata.gz: 99e3f0cb9736fd9ce9cf36eff4a8a0084bacc83212d33328a0e897c1f838b0eed4e0a0882d473f0ccacd4995066cd81cebb7ad390acd38471bdf90496915f23a
7
- data.tar.gz: 36075de1d501f7ae29c17c00f16a145975ea9a7b63b437e1f063bd2baebee20744233d5b62bb7a034d13f23f979be0a1e074a98ee9eeb2ea5f97a729e4ac2d16
6
+ metadata.gz: 7fa557243e1acc57060b9bcc9bb8a390efe31082e5be1f66762c8f4b8e73020d509528b8bfc108119f44107f3f7196601cde471f6c054f67808048ffd2a4cf5a
7
+ data.tar.gz: d354db70f1a6b46411496b2ce415baf68a5c8c087bbf3fd4b578af1031e33ff657b201976985385384f8efe6d19dc99c97a6612e033bd11529eb92fb686baf26
data/.gems ADDED
@@ -0,0 +1,2 @@
1
+ cutest -v 1.2.2
2
+ rack -v 1.6.4
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class SecureHeaders
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -10,46 +10,47 @@ module Rack
10
10
  x_xss_protection: "1; mode=block"
11
11
  }
12
12
 
13
- DEFAULT_HEADERS = {
14
- x_content_type_options: "X-Content-Type-Options",
15
- x_frame_options: "X-Frame-Options",
16
- x_permitted_cross_domain_policies: "X-Permitted-Cross-Domain-Policies",
17
- x_xss_protection: "X-XSS-Protection"
18
- }
19
-
20
- HSTS_HEADER = "Strict-Transport-Security".freeze
21
-
22
13
  def initialize(app, options = {})
14
+ options = DEFAULTS.merge(options)
15
+
23
16
  @app = app
24
- @options = DEFAULTS.merge(options)
17
+ @headers = base_headers(options)
18
+
19
+ if options[:hsts]
20
+ @headers["Strict-Transport-Security"] = hsts_header(options[:hsts])
21
+ end
25
22
  end
26
23
 
27
24
  def call(env)
28
- status, headers, body = @app.call(env)
25
+ tuple = @app.call(env)
26
+ tuple[1].merge!(@headers)
29
27
 
30
- DEFAULT_HEADERS.each do |key, header|
31
- headers[header] = @options[key] if @options[key]
32
- end
28
+ return tuple
29
+ end
30
+
31
+ private
33
32
 
34
- if @options[:hsts]
35
- headers[HSTS_HEADER] = Utils.hsts(@options[:hsts])
33
+ def base_headers(options)
34
+ headers = {
35
+ "X-Content-Type-Options" => options[:x_content_type_options],
36
+ "X-Frame-Options" => options[:x_frame_options],
37
+ "X-Permitted-Cross-Domain-Policies" => options[:x_permitted_cross_domain_policies],
38
+ "X-XSS-Protection" => options[:x_xss_protection],
39
+ }
40
+
41
+ headers.each do |header, value|
42
+ headers.delete(header) if value.nil?
36
43
  end
37
44
 
38
- return [status, headers, body]
45
+ return headers
39
46
  end
40
47
 
41
- module Utils
42
- HSTS_MAX_AGE = "max-age=%s".freeze
43
- HSTS_INCLUDE_SUBDOMAINS = "; includeSubdomains".freeze
44
- HSTS_PRELOAD = "; preload".freeze
45
-
46
- def self.hsts(opts)
47
- header = sprintf(HSTS_MAX_AGE, opts.fetch(:max_age))
48
- header << HSTS_INCLUDE_SUBDOMAINS if opts[:include_subdomains]
49
- header << HSTS_PRELOAD if opts[:preload]
48
+ def hsts_header(options)
49
+ header = sprintf("max-age=%s", options.fetch(:max_age))
50
+ header << "; includeSubdomains" if options[:include_subdomains]
51
+ header << "; preload" if options[:preload]
50
52
 
51
- return header
52
- end
53
+ return header
53
54
  end
54
55
  end
55
56
  end
data/makefile CHANGED
@@ -1,2 +1,2 @@
1
1
  default:
2
- cutest -r ./test/helper.rb ./test/*.rb
2
+ @cutest -r ./test/helper.rb ./test/*.rb
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
14
 
15
- s.add_dependency "rack", "~> 1.6.4"
16
- s.add_development_dependency "bundler", "~> 1.10"
17
- s.add_development_dependency "cutest", "~> 1.2"
15
+ s.add_dependency "rack", "~> 1.6"
16
+ s.add_development_dependency "cutest", "1.2.2"
18
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-secure_headers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodríguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -16,42 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.4
19
+ version: '1.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.4
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.10'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.10'
26
+ version: '1.6'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: cutest
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - '='
46
32
  - !ruby/object:Gem::Version
47
- version: '1.2'
33
+ version: 1.2.2
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - '='
53
39
  - !ruby/object:Gem::Version
54
- version: '1.2'
40
+ version: 1.2.2
55
41
  description: Security related HTTP headers for Rack applications
56
42
  email:
57
43
  - frodsan@protonmail.ch
@@ -59,8 +45,7 @@ executables: []
59
45
  extensions: []
60
46
  extra_rdoc_files: []
61
47
  files:
62
- - ".gitignore"
63
- - Gemfile
48
+ - ".gems"
64
49
  - LICENSE
65
50
  - README.md
66
51
  - lib/rack/secure_headers.rb
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- Gemfile.lock
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec