securenative 0.1.34 → 0.1.39
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/securenative/api_manager.rb +6 -0
- data/lib/securenative/context.rb +1 -1
- data/lib/securenative/event_manager.rb +1 -1
- data/lib/securenative/frameworks/hanami.rb +10 -3
- data/lib/securenative/frameworks/rails.rb +10 -3
- data/lib/securenative/frameworks/sinatra.rb +10 -3
- data/lib/securenative/http_client.rb +1 -1
- data/lib/securenative/utils/request_utils.rb +81 -14
- data/lib/securenative/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f51a9bf80e38a18bca0466b36a1a47266ae8dfe33df9130d0c0f22a8fa17d10e
|
|
4
|
+
data.tar.gz: 8e3e7b2cc512a4de5ff841679eea3a89083744ea281ecd26826a9ae38ccc607f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 975307d2f8e367f0add4255357fb90e53ee3c761f0ae9527023aac385e375d8fe5ddcd60de9c10c9b24aab4468e5e8bf88bce945fb2ffaf4e9404de9f31540cc
|
|
7
|
+
data.tar.gz: 7418c8fad032dde0bb3175d3028336662d313fc0d358664e9f2712aba83dd496c858a7c2cc950f57d0a9a73c80ab26e081f15271b5c6cfdee12e0fd70206ce64
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -20,6 +20,12 @@ module SecureNative
|
|
|
20
20
|
begin
|
|
21
21
|
res = @event_manager.send_sync(event, SecureNative::Enums::ApiRoute::VERIFY)
|
|
22
22
|
ver_result = JSON.parse(res.body)
|
|
23
|
+
if res.code != "200"
|
|
24
|
+
if @options.fail_over_strategy == SecureNative::FailOverStrategy::FAIL_OPEN
|
|
25
|
+
return SecureNative::VerifyResult.new(risk_level: SecureNative::Enums::RiskLevel::LOW, score: 0, triggers: [])
|
|
26
|
+
end
|
|
27
|
+
return VerifyResult.new(risk_level: SecureNative::Enums::RiskLevel::HIGH, score: 1, triggers: [])
|
|
28
|
+
end
|
|
23
29
|
return VerifyResult.new(risk_level: ver_result['riskLevel'], score: ver_result['score'], triggers: ver_result['triggers'])
|
|
24
30
|
rescue StandardError => e
|
|
25
31
|
SecureNative::Log.debug("Failed to call verify; #{e}")
|
data/lib/securenative/context.rb
CHANGED
|
@@ -62,7 +62,7 @@ class EventManager
|
|
|
62
62
|
res = @http_client.post(resource_path, EventManager.serialize(event).to_json)
|
|
63
63
|
|
|
64
64
|
if res.nil? || res.code != '200'
|
|
65
|
-
SecureNative::Log.info("SecureNative failed to call endpoint #{resource_path} with event #{event}
|
|
65
|
+
SecureNative::Log.info("SecureNative failed to call endpoint #{resource_path} with event #{event}")
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
res
|
|
@@ -35,10 +35,17 @@ module SecureNative
|
|
|
35
35
|
|
|
36
36
|
def self.get_headers(request)
|
|
37
37
|
begin
|
|
38
|
-
headers =
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
headers = {}
|
|
39
|
+
|
|
40
|
+
request.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
|
|
41
|
+
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
if headers.length == 0
|
|
45
|
+
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
|
|
46
|
+
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
|
|
47
|
+
}
|
|
48
|
+
end
|
|
42
49
|
return headers
|
|
43
50
|
rescue StandardError
|
|
44
51
|
nil
|
|
@@ -37,10 +37,17 @@ module SecureNative
|
|
|
37
37
|
|
|
38
38
|
def self.get_headers(request)
|
|
39
39
|
begin
|
|
40
|
-
headers =
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
headers = {}
|
|
41
|
+
|
|
42
|
+
request.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
|
|
43
|
+
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
|
|
43
44
|
}
|
|
45
|
+
|
|
46
|
+
if headers.length == 0
|
|
47
|
+
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
|
|
48
|
+
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
|
|
49
|
+
}
|
|
50
|
+
end
|
|
44
51
|
return headers
|
|
45
52
|
rescue StandardError
|
|
46
53
|
nil
|
|
@@ -35,10 +35,17 @@ module SecureNative
|
|
|
35
35
|
|
|
36
36
|
def self.get_headers(request)
|
|
37
37
|
begin
|
|
38
|
-
headers =
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
headers = {}
|
|
39
|
+
|
|
40
|
+
request.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
|
|
41
|
+
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
|
|
41
42
|
}
|
|
43
|
+
|
|
44
|
+
if headers.length == 0
|
|
45
|
+
request.headers.env.select { |k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/ }.each { |header|
|
|
46
|
+
headers[header[0].downcase.gsub("http_", "").gsub("_", "-")] = header[1]
|
|
47
|
+
}
|
|
48
|
+
end
|
|
42
49
|
return headers
|
|
43
50
|
rescue StandardError
|
|
44
51
|
nil
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'ipaddr'
|
|
4
|
+
|
|
3
5
|
module SecureNative
|
|
4
6
|
module Utils
|
|
5
7
|
class RequestUtils
|
|
@@ -24,14 +26,20 @@ module SecureNative
|
|
|
24
26
|
if h.nil?
|
|
25
27
|
h = request.env[self.parse_ip(header)]
|
|
26
28
|
end
|
|
27
|
-
|
|
29
|
+
parsed = self.parse_proxy_header(h, header)
|
|
30
|
+
if self.validate_ip(parsed)
|
|
31
|
+
return parsed
|
|
32
|
+
end
|
|
28
33
|
rescue NoMethodError
|
|
29
34
|
begin
|
|
30
35
|
h = request[header]
|
|
31
36
|
if h.nil?
|
|
32
37
|
h = request.env[self.parse_ip(header)]
|
|
33
38
|
end
|
|
34
|
-
|
|
39
|
+
parsed = self.parse_proxy_header(h, header)
|
|
40
|
+
if self.validate_ip(parsed)
|
|
41
|
+
return parsed
|
|
42
|
+
end
|
|
35
43
|
rescue NoMethodError
|
|
36
44
|
# Ignored
|
|
37
45
|
end
|
|
@@ -40,36 +48,66 @@ module SecureNative
|
|
|
40
48
|
end
|
|
41
49
|
|
|
42
50
|
begin
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
header_value = request.env['HTTP_X_FORWARDED_FOR']
|
|
52
|
+
if header_value.include? ','
|
|
53
|
+
header_value = header_value.split(',')[0]
|
|
54
|
+
end
|
|
55
|
+
if self.validate_ip(header_value)
|
|
56
|
+
return header_value
|
|
57
|
+
end
|
|
45
58
|
rescue NoMethodError
|
|
46
59
|
begin
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
header_value = request['HTTP_X_FORWARDED_FOR']
|
|
61
|
+
if header_value.include? ','
|
|
62
|
+
header_value = header_value.split(',')[0]
|
|
63
|
+
end
|
|
64
|
+
if self.validate_ip(header_value)
|
|
65
|
+
return header_value
|
|
66
|
+
end
|
|
49
67
|
rescue NoMethodError
|
|
50
68
|
# Ignored
|
|
51
69
|
end
|
|
52
70
|
end
|
|
53
71
|
|
|
54
72
|
begin
|
|
55
|
-
|
|
56
|
-
|
|
73
|
+
header_value = request.env['HTTP_X_REAL_IP']
|
|
74
|
+
if header_value.include? ','
|
|
75
|
+
header_value = header_value.split(',')[0]
|
|
76
|
+
end
|
|
77
|
+
if self.validate_ip(header_value)
|
|
78
|
+
return header
|
|
79
|
+
end
|
|
57
80
|
rescue NoMethodError
|
|
58
81
|
begin
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
header_value = request['HTTP_X_REAL_IP']
|
|
83
|
+
if header_value.include? ','
|
|
84
|
+
header_value = header_value.split(',')[0]
|
|
85
|
+
end
|
|
86
|
+
if self.validate_ip(header_value)
|
|
87
|
+
return header_value
|
|
88
|
+
end
|
|
61
89
|
rescue NoMethodError
|
|
62
90
|
# Ignored
|
|
63
91
|
end
|
|
64
92
|
end
|
|
65
93
|
|
|
66
94
|
begin
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
header_value = request.env['REMOTE_ADDR']
|
|
96
|
+
if header_value.include? ','
|
|
97
|
+
header_value = header_value.split(',')[0]
|
|
98
|
+
end
|
|
99
|
+
if self.validate_ip(header_value)
|
|
100
|
+
return header_value
|
|
101
|
+
end
|
|
69
102
|
rescue NoMethodError
|
|
70
103
|
begin
|
|
71
|
-
|
|
72
|
-
|
|
104
|
+
header_value = request['REMOTE_ADDR']
|
|
105
|
+
if header_value.include? ','
|
|
106
|
+
header_value = header_value.split(',')[0]
|
|
107
|
+
end
|
|
108
|
+
if self.validate_ip(header_value)
|
|
109
|
+
return header_value
|
|
110
|
+
end
|
|
73
111
|
rescue NoMethodError
|
|
74
112
|
# Ignored
|
|
75
113
|
end
|
|
@@ -96,6 +134,35 @@ module SecureNative
|
|
|
96
134
|
h = headers.gsub('-', '_')
|
|
97
135
|
return PREFIX + h.upcase
|
|
98
136
|
end
|
|
137
|
+
|
|
138
|
+
def self.parse_proxy_header(headers, header_key)
|
|
139
|
+
h = headers.gsub(header_key + ': ', '')
|
|
140
|
+
if headers.include? ','
|
|
141
|
+
h = h.split(',')[0]
|
|
142
|
+
end
|
|
143
|
+
return h
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def self.validate_ip(ip)
|
|
147
|
+
if ip.nil?
|
|
148
|
+
return false
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
begin
|
|
152
|
+
ipaddr = IPAddr.new(ip)
|
|
153
|
+
if ipaddr.ipv4?
|
|
154
|
+
return true
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
if ipaddr.ipv6?
|
|
158
|
+
return true
|
|
159
|
+
end
|
|
160
|
+
rescue Exception
|
|
161
|
+
# Ignored
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
return false
|
|
165
|
+
end
|
|
99
166
|
end
|
|
100
167
|
end
|
|
101
168
|
end
|
data/lib/securenative/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: securenative
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.39
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SecureNative
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-10-
|
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|