securenative 0.1.30 → 0.1.31
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 +2 -2
- data/lib/securenative/client.rb +4 -0
- data/lib/securenative/context.rb +4 -4
- data/lib/securenative/utils/request_utils.rb +13 -1
- 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: e936efafd72a5c0c1a5014d6649b6fafff6494a117a7dcd04090f031971cc5af
|
4
|
+
data.tar.gz: db9ba27daf67f22e6764632d944a24039b617b71a4364a7180ef792b9e631ee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1009b1d827f473ea051b0e9bfd406508c8e6e9019009c3cb1b43a6aee6d1c551c41dfd1956d9a45e0f2f52eea633a9f183c3327cb93eb7a94c6357570d5c1a6
|
7
|
+
data.tar.gz: 843dd129a073f551ce5878fc788809b3611e98769cb4723ff2563176016be7a26f7190ff0a8d20bc513420dfe067943bf16e7efd52ce1ba51a13e98b203293e6
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -114,7 +114,7 @@ require 'securenative'
|
|
114
114
|
|
115
115
|
def track(request)
|
116
116
|
securenative = SecureNative::Client.instance
|
117
|
-
context =
|
117
|
+
context = securenative.from_http_request(request)
|
118
118
|
|
119
119
|
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
120
120
|
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
@@ -136,7 +136,7 @@ require 'securenative'
|
|
136
136
|
|
137
137
|
def verify(request)
|
138
138
|
securenative = SecureNative::Client.instance
|
139
|
-
context =
|
139
|
+
context = securenative.from_http_request(request)
|
140
140
|
|
141
141
|
event_options = SecureNative::EventOptions.new(event: SecureNative::EventTypes::LOG_IN, user_id: '1234', context: context,
|
142
142
|
user_traits: SecureNative::UserTraits.new(name: 'Your Name', email: 'name@gmail.com', phone: '+1234567890'),
|
data/lib/securenative/client.rb
CHANGED
@@ -42,6 +42,10 @@ module SecureNative
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def from_http_request(request)
|
46
|
+
SecureNative::Context.from_http_request(request, @options)
|
47
|
+
end
|
48
|
+
|
45
49
|
def self.init
|
46
50
|
options = SecureNative::Config::ConfigurationManager.load_config
|
47
51
|
init_with_options(options)
|
data/lib/securenative/context.rb
CHANGED
@@ -21,7 +21,7 @@ module SecureNative
|
|
21
21
|
SecureNative::Context.new
|
22
22
|
end
|
23
23
|
|
24
|
-
def self.from_http_request(request)
|
24
|
+
def self.from_http_request(request, options)
|
25
25
|
client_token = SecureNative::Frameworks::Rails.get_client_token(request)
|
26
26
|
client_token = SecureNative::Frameworks::Sinatra.get_client_token(request) if client_token.nil?
|
27
27
|
client_token = SecureNative::Frameworks::Hanami.get_client_token(request) if client_token.nil?
|
@@ -57,9 +57,9 @@ module SecureNative
|
|
57
57
|
client_token = SecureNative::Utils::RequestUtils.get_secure_header_from_request(headers)
|
58
58
|
end
|
59
59
|
|
60
|
-
SecureNative::Context.new(client_token: client_token, ip: SecureNative::Utils::RequestUtils.get_client_ip_from_request(request),
|
61
|
-
|
62
|
-
|
60
|
+
SecureNative::Context.new(client_token: client_token, ip: SecureNative::Utils::RequestUtils.get_client_ip_from_request(request, options),
|
61
|
+
remote_ip: SecureNative::Utils::RequestUtils.get_remote_ip_from_request(request),
|
62
|
+
headers: headers, url: url, http_method: method || '', body: body)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -5,6 +5,7 @@ module SecureNative
|
|
5
5
|
class RequestUtils
|
6
6
|
SECURENATIVE_COOKIE = '_sn'
|
7
7
|
SECURENATIVE_HEADER = 'x-securenative'
|
8
|
+
PREFIX = 'HTTP_'
|
8
9
|
|
9
10
|
def self.get_secure_header_from_request(headers)
|
10
11
|
begin
|
@@ -15,15 +16,21 @@ module SecureNative
|
|
15
16
|
[]
|
16
17
|
end
|
17
18
|
|
18
|
-
def self.get_client_ip_from_request(request, options
|
19
|
+
def self.get_client_ip_from_request(request, options)
|
19
20
|
unless options.nil?
|
20
21
|
for header in options.proxy_headers do
|
21
22
|
begin
|
22
23
|
h = request.env[header]
|
24
|
+
unless !h.nil?
|
25
|
+
h = request.env[self.parse_ip(header)]
|
26
|
+
end
|
23
27
|
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
24
28
|
rescue NoMethodError
|
25
29
|
begin
|
26
30
|
h = request[header]
|
31
|
+
unless !h.nil?
|
32
|
+
h = request.env[self.parse_ip(header)]
|
33
|
+
end
|
27
34
|
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
28
35
|
rescue NoMethodError
|
29
36
|
end
|
@@ -79,6 +86,11 @@ module SecureNative
|
|
79
86
|
''
|
80
87
|
end
|
81
88
|
end
|
89
|
+
|
90
|
+
def self.parse_ip(headers)
|
91
|
+
h = headers.gsub('-', '_')
|
92
|
+
return PREFIX + h.upcase
|
93
|
+
end
|
82
94
|
end
|
83
95
|
end
|
84
96
|
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.31
|
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-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|