securenative 0.1.30 → 0.1.31

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
  SHA256:
3
- metadata.gz: 37b0720aab5431b97f1b2313e9e1e88d6a3ce712ba342575c86884a5d3ed9f7c
4
- data.tar.gz: 74258ad8d16b072378bda84119bb65831cb1441f186fcb49a893308d777249d6
3
+ metadata.gz: e936efafd72a5c0c1a5014d6649b6fafff6494a117a7dcd04090f031971cc5af
4
+ data.tar.gz: db9ba27daf67f22e6764632d944a24039b617b71a4364a7180ef792b9e631ee6
5
5
  SHA512:
6
- metadata.gz: bb0ce8d22b7b1ce832c49a3690856312b298cc8cc55046ebe966cf7ddb410079ae5d13cc93a4fd25b4a111fd971ec7be9782f92b5716103bba2842ce72607d8e
7
- data.tar.gz: 17dece79e7f8dabed7fd270d1da3d7cc50f94691bfed65324e45b961ac8bd0a33371d4390f941cb3fa460e24a72fb86487a466ceaff91ec6d23595fc6cb6b9a8
6
+ metadata.gz: f1009b1d827f473ea051b0e9bfd406508c8e6e9019009c3cb1b43a6aee6d1c551c41dfd1956d9a45e0f2f52eea633a9f183c3327cb93eb7a94c6357570d5c1a6
7
+ data.tar.gz: 843dd129a073f551ce5878fc788809b3611e98769cb4723ff2563176016be7a26f7190ff0a8d20bc513420dfe067943bf16e7efd52ce1ba51a13e98b203293e6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- securenative (0.1.30)
4
+ securenative (0.1.31)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 = SecureNative::Context.from_http_request(request)
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 = SecureNative::Context.from_http_request(request)
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'),
@@ -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)
@@ -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
- remote_ip: SecureNative::Utils::RequestUtils.get_remote_ip_from_request(request),
62
- headers: headers, url: url, http_method: method || '', body: body)
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 = nil)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SecureNative
4
- VERSION = '0.1.30'
4
+ VERSION = '0.1.31'
5
5
  end
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.30
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-01 00:00:00.000000000 Z
11
+ date: 2020-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler