rack-secure_headers 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -3
- data/lib/rack/secure_headers.rb +5 -4
- data/lib/rack/secure_headers/version.rb +1 -1
- data/test/helper.rb +3 -1
- data/test/secure_headers_test.rb +53 -0
- metadata +42 -16
- data/.gems +0 -2
- data/makefile +0 -2
- data/rack-secure_headers.gemspec +0 -17
- data/test/secure_headers.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c176a48717c3d1afa227f16b0cf649eae502b935
|
4
|
+
data.tar.gz: a261ce0c5d80fc188d574459a7eff2ae728d7e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3640b92a0a20c00d4604118ae9b078c7c4d45a65bbccb504a952d628872ab3d55796428bde1ab2534affbef21861815ebe7d70562a116b62c817feaace4df0c
|
7
|
+
data.tar.gz: df6304b967ac4fe810aa9171717214b0a46b8c7dfe109d0622eb360731bb873a61e44b098cca870f8488ea86894c7b5e1a148049713ea9e03a38b55cfbe8b820
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
rack-secure_headers
|
1
|
+
rack-secure_headers [![Build Status](https://travis-ci.org/frodsan/rack-secure_headers.svg)](https://travis-ci.org/frodsan/rack-secure_headers)
|
2
2
|
-------------------
|
3
3
|
|
4
4
|
Security related HTTP headers for Rack applications.
|
@@ -8,6 +8,27 @@ Description
|
|
8
8
|
|
9
9
|
Implements OWASP's [List of useful HTTP headers][owasp].
|
10
10
|
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "rack-secure_headers"
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```
|
23
|
+
$ bundle
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```
|
29
|
+
$ gem install rack-secure_headers
|
30
|
+
```
|
31
|
+
|
11
32
|
Usage
|
12
33
|
-----
|
13
34
|
|
@@ -93,16 +114,39 @@ TODO
|
|
93
114
|
- [ ] HTTP Public Key Pinning (HPKP).
|
94
115
|
- [ ] Content Security Policy (CSP).
|
95
116
|
|
96
|
-
|
117
|
+
Contributing
|
97
118
|
------------
|
98
119
|
|
120
|
+
Fork the project with:
|
121
|
+
|
99
122
|
```
|
100
|
-
$
|
123
|
+
$ git clone git@github.com:frodsan/rack-secure_headers.git
|
124
|
+
```
|
125
|
+
|
126
|
+
To install dependencies, use:
|
127
|
+
|
101
128
|
```
|
129
|
+
$ bundle install
|
130
|
+
```
|
131
|
+
|
132
|
+
To run the test suite, do:
|
133
|
+
|
134
|
+
```
|
135
|
+
$ rake test
|
136
|
+
```
|
137
|
+
|
138
|
+
For bug reports and pull requests use [GitHub][issues].
|
139
|
+
|
140
|
+
License
|
141
|
+
-------
|
142
|
+
|
143
|
+
This gem is released under the [MIT License][mit].
|
102
144
|
|
103
145
|
[clickjacking]: https://www.owasp.org/index.php/Clickjacking
|
104
146
|
[hsts-form]: https://hstspreload.appspot.com/
|
147
|
+
[issues]: https://github.com/frodsan/rack-secure_headers/issues
|
105
148
|
[mime-sniffing]: https://msdn.microsoft.com/library/gg622941(v=vs.85).aspx
|
149
|
+
[mit]: http://www.opensource.org/licenses/MIT
|
106
150
|
[owasp]: https://www.owasp.org/index.php/List_of_useful_HTTP_headers
|
107
151
|
[pcdp]: https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html
|
108
152
|
[xss]: https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
|
data/lib/rack/secure_headers.rb
CHANGED
@@ -22,10 +22,11 @@ module Rack
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def call(env)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
return @app.call(env).tap do |_, headers, _|
|
26
|
+
@headers.each do |key, value|
|
27
|
+
headers[key] ||= value
|
28
|
+
end
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
32
|
private
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class App
|
4
|
+
def call(env)
|
5
|
+
return [200, {}, [""]]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class SecureHeadersTest < Minitest::Test
|
10
|
+
setup do
|
11
|
+
@app = App.new
|
12
|
+
end
|
13
|
+
|
14
|
+
test "defaults" do
|
15
|
+
middleware = Rack::SecureHeaders.new(@app)
|
16
|
+
headers = middleware.call({})[1]
|
17
|
+
|
18
|
+
expected = {
|
19
|
+
"X-Content-Type-Options" => "nosniff",
|
20
|
+
"X-Frame-Options" => "SAMEORIGIN",
|
21
|
+
"X-Permitted-Cross-Domain-Policies" => "none",
|
22
|
+
"X-XSS-Protection" => "1; mode=block",
|
23
|
+
"Strict-Transport-Security" => "max-age=31536000; includeSubdomains",
|
24
|
+
}
|
25
|
+
|
26
|
+
assert_equal expected, headers
|
27
|
+
end
|
28
|
+
|
29
|
+
test "nil" do
|
30
|
+
headers = Rack::SecureHeaders::DEFAULTS.keys
|
31
|
+
options = headers.map { |h| [h, nil] }.to_h
|
32
|
+
|
33
|
+
middleware = Rack::SecureHeaders.new(@app, options)
|
34
|
+
headers = middleware.call({})[1]
|
35
|
+
|
36
|
+
assert_equal Hash.new, headers
|
37
|
+
end
|
38
|
+
|
39
|
+
test "hsts options" do
|
40
|
+
middleware = Rack::SecureHeaders.new(@app, hsts: { max_age: 1 })
|
41
|
+
headers = middleware.call({})[1]
|
42
|
+
|
43
|
+
assert_equal "max-age=1", headers["Strict-Transport-Security"]
|
44
|
+
|
45
|
+
options = { max_age: 1, include_subdomains: true, preload: true }
|
46
|
+
middleware = Rack::SecureHeaders.new(@app, hsts: options)
|
47
|
+
headers = middleware.call({})[1]
|
48
|
+
|
49
|
+
expected = "max-age=1; includeSubdomains; preload"
|
50
|
+
|
51
|
+
assert_equal expected, headers["Strict-Transport-Security"]
|
52
|
+
end
|
53
|
+
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.
|
4
|
+
version: 0.0.3
|
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:
|
11
|
+
date: 2016-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -25,36 +25,60 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '5.8'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-sugar
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
41
69
|
description: Security related HTTP headers for Rack applications
|
42
|
-
email:
|
43
|
-
- frodsan@protonmail.ch
|
70
|
+
email: frodsan@protonmail.ch
|
44
71
|
executables: []
|
45
72
|
extensions: []
|
46
73
|
extra_rdoc_files: []
|
47
74
|
files:
|
48
|
-
- ".gems"
|
49
75
|
- LICENSE
|
50
76
|
- README.md
|
51
77
|
- lib/rack/secure_headers.rb
|
52
78
|
- lib/rack/secure_headers/version.rb
|
53
|
-
- makefile
|
54
|
-
- rack-secure_headers.gemspec
|
55
79
|
- test/helper.rb
|
56
|
-
- test/
|
57
|
-
homepage: https://github.com/
|
80
|
+
- test/secure_headers_test.rb
|
81
|
+
homepage: https://github.com/frodsan/rack-secure_headers
|
58
82
|
licenses:
|
59
83
|
- MIT
|
60
84
|
metadata: {}
|
@@ -74,8 +98,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
98
|
version: '0'
|
75
99
|
requirements: []
|
76
100
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
101
|
+
rubygems_version: 2.5.0
|
78
102
|
signing_key:
|
79
103
|
specification_version: 4
|
80
104
|
summary: Security related HTTP headers for Rack applications
|
81
|
-
test_files:
|
105
|
+
test_files:
|
106
|
+
- test/helper.rb
|
107
|
+
- test/secure_headers_test.rb
|
data/.gems
DELETED
data/makefile
DELETED
data/rack-secure_headers.gemspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require_relative "lib/rack/secure_headers/version"
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "rack-secure_headers"
|
5
|
-
s.version = Rack::SecureHeaders::VERSION
|
6
|
-
s.summary = "Security related HTTP headers for Rack applications"
|
7
|
-
s.description = s.summary
|
8
|
-
s.authors = ["Francesco Rodríguez"]
|
9
|
-
s.email = ["frodsan@protonmail.ch"]
|
10
|
-
s.homepage = "https://github.com/harmoni/rack-secure_headers"
|
11
|
-
s.license = "MIT"
|
12
|
-
|
13
|
-
s.files = `git ls-files`.split("\n")
|
14
|
-
|
15
|
-
s.add_dependency "rack", "~> 1.6"
|
16
|
-
s.add_development_dependency "cutest", "1.2.2"
|
17
|
-
end
|
data/test/secure_headers.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require_relative "helper"
|
2
|
-
|
3
|
-
class App
|
4
|
-
def call(env)
|
5
|
-
return [200, {}, [""]]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
setup do
|
10
|
-
App.new
|
11
|
-
end
|
12
|
-
|
13
|
-
test "defaults" do |app|
|
14
|
-
middleware = Rack::SecureHeaders.new(app)
|
15
|
-
headers = middleware.call({})[1]
|
16
|
-
|
17
|
-
expected = {
|
18
|
-
"X-Content-Type-Options" => "nosniff",
|
19
|
-
"X-Frame-Options" => "SAMEORIGIN",
|
20
|
-
"X-Permitted-Cross-Domain-Policies" => "none",
|
21
|
-
"X-XSS-Protection" => "1; mode=block",
|
22
|
-
"Strict-Transport-Security" => "max-age=31536000; includeSubdomains",
|
23
|
-
}
|
24
|
-
|
25
|
-
assert_equal expected, headers
|
26
|
-
end
|
27
|
-
|
28
|
-
test "nil" do |app|
|
29
|
-
headers = Rack::SecureHeaders::DEFAULTS.keys
|
30
|
-
options = headers.map { |h| [h, nil] }.to_h
|
31
|
-
|
32
|
-
middleware = Rack::SecureHeaders.new(app, options)
|
33
|
-
headers = middleware.call({})[1]
|
34
|
-
|
35
|
-
assert_equal Hash.new, headers
|
36
|
-
end
|
37
|
-
|
38
|
-
test "hsts options" do |app|
|
39
|
-
middleware = Rack::SecureHeaders.new(app, hsts: { max_age: 1 })
|
40
|
-
headers = middleware.call({})[1]
|
41
|
-
|
42
|
-
assert_equal "max-age=1", headers["Strict-Transport-Security"]
|
43
|
-
|
44
|
-
options = { max_age: 1, include_subdomains: true, preload: true }
|
45
|
-
middleware = Rack::SecureHeaders.new(app, hsts: options)
|
46
|
-
headers = middleware.call({})[1]
|
47
|
-
|
48
|
-
expected = "max-age=1; includeSubdomains; preload"
|
49
|
-
|
50
|
-
assert_equal expected, headers["Strict-Transport-Security"]
|
51
|
-
end
|