simple-hsts 0.1.2
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.
- checksums.yaml +7 -0
- data/lib/simple-hsts.rb +38 -0
- metadata +42 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 463f4e65649aac3f42088094842e7413aa906581d376d6a665d97aba1d082e2c
|
4
|
+
data.tar.gz: b13b4cea8754491c0bd63ad776fecec749a4a1febd101647971a43f7eea70348
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea0ad6d7f6281f232686241e40898606a728575d085bf49ebabcd7d50ba8b3b44d3573ed64f97fe4c7d62b371c7bd5dc9734f51d0fd48c45d241c9452f7ec94c
|
7
|
+
data.tar.gz: 295323910797801b77e23d99fb09886b63a71ef46ab5832c1b678152b7800993298c43125ed7026615fb940a29292091c0b48261fcf52925e7d1b77e96895002
|
data/lib/simple-hsts.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rack
|
2
|
+
module TlsTools
|
3
|
+
|
4
|
+
# http://en.wikipedia.org/wiki/Strict_Transport_Security
|
5
|
+
class Hsts
|
6
|
+
|
7
|
+
# a year
|
8
|
+
DEFAULT_MAX_AGE = 3600 * 24 * 365
|
9
|
+
|
10
|
+
def initialize(app, options = {})
|
11
|
+
@app = app
|
12
|
+
@options = {
|
13
|
+
enable: true,
|
14
|
+
max_age: DEFAULT_MAX_AGE,
|
15
|
+
subdomains: false,
|
16
|
+
}.merge(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
@app.call(env).tap do |response|
|
21
|
+
@request = Rack::Request.new env
|
22
|
+
if @request.ssl? && @options[:enable]
|
23
|
+
add_hsts_header! response[1]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def add_hsts_header!(headers)
|
31
|
+
val = "max-age=#{@options[:max_age].to_i}"
|
32
|
+
val += "; includeSubDomains" if @options[:subdomains]
|
33
|
+
headers['Strict-Transport-Security'] = val
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-hsts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SuperJenn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/simple-hsts.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubygems_version: 3.5.7
|
39
|
+
signing_key:
|
40
|
+
specification_version: 4
|
41
|
+
summary: Simple way to add HSTS to Rails apps
|
42
|
+
test_files: []
|