securenative 0.1.17 → 0.1.23
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/.github/workflows/ci.yml +5 -2
- data/.github/workflows/test.yml +5 -2
- data/.gitignore +3 -1
- data/Gemfile +6 -4
- data/Gemfile.lock +234 -25
- data/README.md +37 -32
- data/lib/api_manager.rb +39 -0
- data/lib/config/configuration_builder.rb +27 -0
- data/lib/config/configuration_manager.rb +56 -0
- data/lib/config/securenative_options.rb +23 -0
- data/lib/context/hanami_context.rb +42 -0
- data/lib/context/rails_context.rb +44 -0
- data/lib/context/securenative_context.rb +67 -0
- data/lib/context/sinatra_context.rb +42 -0
- data/lib/enums/api_route.rb +6 -0
- data/lib/enums/event_types.rb +23 -0
- data/lib/enums/failover_strategy.rb +6 -0
- data/lib/enums/risk_level.rb +7 -0
- data/lib/errors/securenative_config_error.rb +4 -0
- data/lib/errors/securenative_http_error.rb +4 -0
- data/lib/errors/securenative_invalid_options_error.rb +4 -0
- data/lib/errors/securenative_invalid_uri_error.rb +4 -0
- data/lib/errors/securenative_parse_error.rb +4 -0
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/lib/errors/securenative_sdk_error.rb +4 -0
- data/lib/event_manager.rb +157 -0
- data/lib/{securenative/http/http_response.rb → http/secure_native_http_response.rb} +4 -2
- data/lib/http/securenative_http_client.rb +50 -0
- data/lib/{securenative/models → models}/client_token.rb +2 -0
- data/lib/{securenative/models → models}/device.rb +3 -1
- data/lib/models/event_options.rb +37 -0
- data/lib/{securenative/models → models}/request_context.rb +7 -4
- data/lib/models/request_options.rb +12 -0
- data/lib/models/sdk_event.rb +49 -0
- data/lib/{securenative/models → models}/user_traits.rb +4 -2
- data/lib/{securenative/models → models}/verify_result.rb +8 -2
- data/lib/securenative.rb +83 -0
- data/lib/utils/date_utils.rb +9 -0
- data/lib/utils/encryption_utils.rb +49 -0
- data/lib/{securenative/utils → utils}/ip_utils.rb +7 -6
- data/lib/utils/request_utils.rb +69 -0
- data/lib/{securenative/logger.rb → utils/secure_native_logger.rb} +5 -3
- data/lib/{securenative/utils → utils}/signature_utils.rb +4 -2
- data/lib/utils/utils.rb +9 -0
- data/lib/utils/version_utils.rb +11 -0
- data/out/production/securenative-ruby/api_manager.rb +39 -0
- data/out/production/securenative-ruby/config/configuration_builder.rb +27 -0
- data/out/production/securenative-ruby/config/configuration_manager.rb +56 -0
- data/out/production/securenative-ruby/config/securenative_options.rb +23 -0
- data/out/production/securenative-ruby/context/hanami_context.rb +42 -0
- data/out/production/securenative-ruby/context/rails_context.rb +44 -0
- data/out/production/securenative-ruby/context/securenative_context.rb +67 -0
- data/out/production/securenative-ruby/context/sinatra_context.rb +42 -0
- data/out/production/securenative-ruby/enums/api_route.rb +6 -0
- data/out/production/securenative-ruby/enums/event_types.rb +23 -0
- data/out/production/securenative-ruby/enums/failover_strategy.rb +6 -0
- data/out/production/securenative-ruby/enums/risk_level.rb +7 -0
- data/out/production/securenative-ruby/errors/securenative_config_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_http_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb +4 -0
- data/out/production/securenative-ruby/errors/securenative_sdk_error.rb +4 -0
- data/out/production/securenative-ruby/event_manager.rb +157 -0
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +12 -0
- data/out/production/securenative-ruby/http/securenative_http_client.rb +50 -0
- data/out/production/securenative-ruby/models/client_token.rb +12 -0
- data/out/production/securenative-ruby/models/device.rb +10 -0
- data/out/production/securenative-ruby/models/event_options.rb +37 -0
- data/out/production/securenative-ruby/models/request_context.rb +18 -0
- data/out/production/securenative-ruby/models/request_options.rb +12 -0
- data/out/production/securenative-ruby/models/sdk_event.rb +49 -0
- data/out/production/securenative-ruby/models/user_traits.rb +13 -0
- data/out/production/securenative-ruby/models/verify_result.rb +16 -0
- data/out/production/securenative-ruby/securenative.rb +83 -0
- data/out/production/securenative-ruby/utils/date_utils.rb +9 -0
- data/out/production/securenative-ruby/utils/encryption_utils.rb +49 -0
- data/out/production/securenative-ruby/utils/ip_utils.rb +23 -0
- data/out/production/securenative-ruby/utils/request_utils.rb +69 -0
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +44 -0
- data/out/production/securenative-ruby/utils/signature_utils.rb +16 -0
- data/out/production/securenative-ruby/utils/utils.rb +9 -0
- data/out/production/securenative-ruby/utils/version_utils.rb +11 -0
- data/out/test/securenative-ruby/spec_api_manager.rb +87 -0
- data/out/test/securenative-ruby/spec_context_builder.rb +87 -0
- data/out/test/securenative-ruby/spec_date_utils.rb +13 -0
- data/out/test/securenative-ruby/spec_encryption_utils.rb +26 -0
- data/out/test/securenative-ruby/spec_event_manager.rb +93 -0
- data/out/test/securenative-ruby/spec_helper.rb +28 -0
- data/out/test/securenative-ruby/spec_ip_utils.rb +41 -0
- data/out/test/securenative-ruby/spec_request_utils.rb +25 -0
- data/out/test/securenative-ruby/spec_sdk_event.rb +24 -0
- data/out/test/securenative-ruby/spec_securenative.rb +61 -0
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +31 -0
- data/out/test/securenative-ruby/spec_signature_utils.rb +18 -0
- data/out/test/securenative-ruby/spec_version_util.rb +10 -0
- data/securenative.gemspec +2 -2
- metadata +93 -43
- data/.travis.yml +0 -6
- data/VERSION +0 -1
- data/lib/securenative/api_manager.rb +0 -30
- data/lib/securenative/config/configuration_builder.rb +0 -26
- data/lib/securenative/config/configuration_manager.rb +0 -53
- data/lib/securenative/config/securenative_options.rb +0 -18
- data/lib/securenative/context/context_builder.rb +0 -59
- data/lib/securenative/context/securenative_context.rb +0 -14
- data/lib/securenative/enums/api_route.rb +0 -4
- data/lib/securenative/enums/event_types.rb +0 -21
- data/lib/securenative/enums/failover_strategy.rb +0 -4
- data/lib/securenative/enums/risk_level.rb +0 -5
- data/lib/securenative/event_manager.rb +0 -150
- data/lib/securenative/event_options_builder.rb +0 -30
- data/lib/securenative/exceptions/securenative_config_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_http_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_options_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_invalid_uri_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_parse_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_Illegal_state_exception.rb +0 -2
- data/lib/securenative/exceptions/securenative_sdk_exception.rb +0 -2
- data/lib/securenative/http/securenative_http_client.rb +0 -30
- data/lib/securenative/models/event_options.rb +0 -13
- data/lib/securenative/models/request_options.rb +0 -10
- data/lib/securenative/models/sdk_event.rb +0 -25
- data/lib/securenative/securenative.iml +0 -9
- data/lib/securenative/securenative.rb +0 -82
- data/lib/securenative/utils/date_utils.rb +0 -7
- data/lib/securenative/utils/encryption_utils.rb +0 -38
- data/lib/securenative/utils/request_utils.rb +0 -21
- data/lib/securenative/utils/utils.rb +0 -9
- data/lib/securenative/utils/version_utils.rb +0 -10
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'logger'
|
2
4
|
|
3
|
-
class
|
5
|
+
class SecureNativeLogger
|
4
6
|
@logger = Logger.new(STDOUT)
|
5
7
|
|
6
|
-
def self.init_logger(level)
|
8
|
+
def self.init_logger(level = 'DEBUG')
|
7
9
|
@logger.level = case level
|
8
10
|
when 'WARN'
|
9
11
|
Logger::WARN
|
@@ -39,4 +41,4 @@ class Logger
|
|
39
41
|
def self.error(msg)
|
40
42
|
@logger.error(msg)
|
41
43
|
end
|
42
|
-
end
|
44
|
+
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'openssl'
|
2
4
|
|
3
5
|
class SignatureUtils
|
4
|
-
SIGNATURE_HEADER = 'x-securenative'
|
6
|
+
SIGNATURE_HEADER = 'x-securenative'
|
5
7
|
|
6
8
|
def self.valid_signature?(api_key, payload, header_signature)
|
7
9
|
key = api_key.encode('utf-8')
|
@@ -11,4 +13,4 @@ class SignatureUtils
|
|
11
13
|
rescue StandardError
|
12
14
|
false
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
data/lib/utils/utils.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'models/sdk_event'
|
4
|
+
require 'enums/failover_strategy'
|
5
|
+
require 'enums/risk_level'
|
6
|
+
require 'enums/api_route'
|
7
|
+
require 'models/verify_result'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
class ApiManager
|
11
|
+
def initialize(event_manager, securenative_options)
|
12
|
+
@event_manager = event_manager
|
13
|
+
@options = securenative_options
|
14
|
+
end
|
15
|
+
|
16
|
+
def track(event_options)
|
17
|
+
SecureNativeLogger.debug('Track event call')
|
18
|
+
event = SDKEvent.new(event_options, @options)
|
19
|
+
@event_manager.send_async(event, ApiRoute::TRACK)
|
20
|
+
end
|
21
|
+
|
22
|
+
def verify(event_options)
|
23
|
+
SecureNativeLogger.debug('Verify event call')
|
24
|
+
event = SDKEvent.new(event_options, @options)
|
25
|
+
|
26
|
+
begin
|
27
|
+
res = @event_manager.send_sync(event, ApiRoute::VERIFY, false)
|
28
|
+
ver_result = JSON.parse(res.body)
|
29
|
+
return VerifyResult.new(risk_level: ver_result['riskLevel'], score: ver_result['score'], triggers: ver_result['triggers'])
|
30
|
+
rescue StandardError => e
|
31
|
+
SecureNativeLogger.debug("Failed to call verify; #{e}")
|
32
|
+
end
|
33
|
+
if @options.fail_over_strategy == FailOverStrategy::FAIL_OPEN
|
34
|
+
return VerifyResult.new(risk_level: RiskLevel::LOW, score: 0, triggers: nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
VerifyResult.new(risk_level: RiskLevel::HIGH, score: 1, triggers: nil)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'enums/failover_strategy'
|
4
|
+
|
5
|
+
class ConfigurationBuilder
|
6
|
+
attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
7
|
+
attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
8
|
+
|
9
|
+
def initialize(api_key: nil, api_url: 'https://api.securenative.com/collector/api/v1', interval: 1000,
|
10
|
+
max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: 'FATAL',
|
11
|
+
fail_over_strategy: FailOverStrategy::FAIL_OPEN, proxy_headers: [])
|
12
|
+
@api_key = api_key
|
13
|
+
@api_url = api_url
|
14
|
+
@interval = interval
|
15
|
+
@max_events = max_events
|
16
|
+
@timeout = timeout
|
17
|
+
@auto_send = auto_send
|
18
|
+
@disable = disable
|
19
|
+
@log_level = log_level
|
20
|
+
@fail_over_strategy = fail_over_strategy
|
21
|
+
@proxy_headers = proxy_headers
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.default_securenative_options
|
25
|
+
SecureNativeOptions.new
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'config/configuration_builder'
|
5
|
+
|
6
|
+
class ConfigurationManager
|
7
|
+
DEFAULT_CONFIG_FILE = 'securenative.yml'
|
8
|
+
CUSTOM_CONFIG_FILE_ENV_NAME = 'SECURENATIVE_CONFIG_FILE'
|
9
|
+
@config = nil
|
10
|
+
|
11
|
+
def self.read_resource_file(resource_path)
|
12
|
+
properties = {}
|
13
|
+
begin
|
14
|
+
@config = YAML.load_file(resource_path)
|
15
|
+
properties = @config unless @config.nil?
|
16
|
+
rescue StandardError => e
|
17
|
+
SecureNativeLogger.error("Could not parse config file #{resource_path}; #{e}")
|
18
|
+
end
|
19
|
+
properties
|
20
|
+
end
|
21
|
+
|
22
|
+
def self._get_resource_path(env_name)
|
23
|
+
Env.fetch(env_name, ENV[DEFAULT_CONFIG_FILE])
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.config_builder
|
27
|
+
ConfigurationBuilder.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def self._get_env_or_default(properties, key, default)
|
31
|
+
return ENV[key] if ENV[key]
|
32
|
+
return properties[key] if properties[key]
|
33
|
+
|
34
|
+
default
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.load_config
|
38
|
+
options = ConfigurationBuilder.default_securenative_options
|
39
|
+
|
40
|
+
resource_path = DEFAULT_CONFIG_FILE
|
41
|
+
resource_path = ENV[CUSTOM_CONFIG_FILE_ENV_NAME] unless ENV[CUSTOM_CONFIG_FILE_ENV_NAME].nil?
|
42
|
+
|
43
|
+
properties = read_resource_file(resource_path)
|
44
|
+
|
45
|
+
ConfigurationBuilder.new(api_key: _get_env_or_default(properties, 'SECURENATIVE_API_KEY', options.api_key),
|
46
|
+
api_url: _get_env_or_default(properties, 'SECURENATIVE_API_URL', options.api_url),
|
47
|
+
interval: _get_env_or_default(properties, 'SECURENATIVE_INTERVAL', options.interval),
|
48
|
+
max_events: _get_env_or_default(properties, 'SECURENATIVE_MAX_EVENTS', options.max_events),
|
49
|
+
timeout: _get_env_or_default(properties, 'SECURENATIVE_TIMEOUT', options.timeout),
|
50
|
+
auto_send: _get_env_or_default(properties, 'SECURENATIVE_AUTO_SEND', options.auto_send),
|
51
|
+
disable: _get_env_or_default(properties, 'SECURENATIVE_DISABLE', options.disable),
|
52
|
+
log_level: _get_env_or_default(properties, 'SECURENATIVE_LOG_LEVEL', options.log_level),
|
53
|
+
fail_over_strategy: _get_env_or_default(properties, 'SECURENATIVE_FAILOVER_STRATEGY', options.fail_over_strategy),
|
54
|
+
proxy_headers: _get_env_or_default(properties, 'SECURENATIVE_PROXY_HEADERS', options.proxy_headers))
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'enums/failover_strategy'
|
4
|
+
|
5
|
+
class SecureNativeOptions
|
6
|
+
attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
7
|
+
attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
8
|
+
|
9
|
+
def initialize(api_key: nil, api_url: "https://api.securenative.com/collector/api/v1", interval: 1000,
|
10
|
+
max_events: 1000, timeout: 1500, auto_send: true, disable: false, log_level: "FATAL",
|
11
|
+
fail_over_strategy: FailOverStrategy::FAIL_OPEN, proxy_headers: [])
|
12
|
+
@api_key = api_key
|
13
|
+
@api_url = api_url
|
14
|
+
@interval = interval
|
15
|
+
@max_events = max_events
|
16
|
+
@timeout = timeout
|
17
|
+
@auto_send = auto_send
|
18
|
+
@disable = disable
|
19
|
+
@log_level = log_level
|
20
|
+
@fail_over_strategy = fail_over_strategy
|
21
|
+
@proxy_headers = proxy_headers
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class HanamiContext
|
4
|
+
SECURENATIVE_COOKIE = '_sn'
|
5
|
+
|
6
|
+
def self.get_client_token(request)
|
7
|
+
begin
|
8
|
+
request.env[SECURENATIVE_COOKIE]
|
9
|
+
rescue StandardError
|
10
|
+
begin
|
11
|
+
request.cookies[SECURENATIVE_COOKIE]
|
12
|
+
rescue StandardError
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_url(request)
|
19
|
+
begin
|
20
|
+
request.env['REQUEST_PATH']
|
21
|
+
rescue StandardError
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_method(request)
|
27
|
+
begin
|
28
|
+
request.request_method
|
29
|
+
rescue StandardError
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_headers(request)
|
35
|
+
begin
|
36
|
+
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
37
|
+
{ 'user-agent' => request.env['HTTP_USER_AGENT'] }
|
38
|
+
rescue StandardError
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RailsContext
|
4
|
+
SECURENATIVE_COOKIE = '_sn'
|
5
|
+
|
6
|
+
def self.get_client_token(request)
|
7
|
+
begin
|
8
|
+
request.cookies[SECURENATIVE_COOKIE]
|
9
|
+
rescue StandardError
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_url(request)
|
15
|
+
begin
|
16
|
+
# Rails >= 3.x
|
17
|
+
request.fullpath
|
18
|
+
rescue StandardError
|
19
|
+
begin
|
20
|
+
# Rails < 3.x & Sinatra
|
21
|
+
request.url if url.nil?
|
22
|
+
rescue StandardError
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_method(request)
|
29
|
+
begin
|
30
|
+
request.method
|
31
|
+
rescue StandardError
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_headers(request)
|
37
|
+
begin
|
38
|
+
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
39
|
+
{ 'user-agent' => request.env['HTTP_USER_AGENT'] }
|
40
|
+
rescue StandardError
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'utils/request_utils'
|
4
|
+
require 'utils/utils'
|
5
|
+
require 'context/rails_context'
|
6
|
+
require 'context/hanami_context'
|
7
|
+
require 'context/sinatra_context'
|
8
|
+
|
9
|
+
class SecureNativeContext
|
10
|
+
attr_reader :client_token, :ip, :remote_ip, :headers, :url, :http_method, :body
|
11
|
+
attr_writer :client_token, :ip, :remote_ip, :headers, :url, :http_method, :body
|
12
|
+
|
13
|
+
SECURENATIVE_COOKIE = '_sn'
|
14
|
+
|
15
|
+
def initialize(client_token: '', ip: '', remote_ip: '', headers: nil, url: '', http_method: '', body: '')
|
16
|
+
@client_token = client_token
|
17
|
+
@ip = ip
|
18
|
+
@remote_ip = remote_ip
|
19
|
+
@headers = headers
|
20
|
+
@url = url
|
21
|
+
@http_method = http_method
|
22
|
+
@body = body
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.default_context_builder
|
26
|
+
SecureNativeContext.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.from_http_request(request)
|
30
|
+
client_token = RailsContext.get_client_token(request)
|
31
|
+
client_token = SinatraContext.get_client_token(request) if client_token.nil?
|
32
|
+
client_token = HanamiContext.get_client_token(request) if client_token.nil?
|
33
|
+
|
34
|
+
begin
|
35
|
+
headers = RailsContext.get_headers(request)
|
36
|
+
headers = SinatraContext.get_headers(request) if headers.nil?
|
37
|
+
headers = HanamiContext.get_headers(request) if headers.nil?
|
38
|
+
|
39
|
+
# Standard Ruby request
|
40
|
+
headers = request.header.to_hash if headers.nil?
|
41
|
+
rescue StandardError
|
42
|
+
headers = []
|
43
|
+
end
|
44
|
+
|
45
|
+
url = RailsContext.get_url(request)
|
46
|
+
url = SinatraContext.get_url(request) if url.nil?
|
47
|
+
url = HanamiContext.get_url(request) if url.nil?
|
48
|
+
url = '' if url.nil?
|
49
|
+
|
50
|
+
method = RailsContext.get_method(request)
|
51
|
+
method = SinatraContext.get_method(request) if method.nil?
|
52
|
+
method = HanamiContext.get_method(request) if method.nil?
|
53
|
+
method = '' if method.nil?
|
54
|
+
|
55
|
+
begin
|
56
|
+
body = request.body.to_s
|
57
|
+
rescue StandardError
|
58
|
+
body = ''
|
59
|
+
end
|
60
|
+
|
61
|
+
client_token = RequestUtils.get_secure_header_from_request(headers) if Utils.null_or_empty?(client_token)
|
62
|
+
|
63
|
+
SecureNativeContext.new(client_token: client_token, ip: RequestUtils.get_client_ip_from_request(request),
|
64
|
+
remote_ip: RequestUtils.get_remote_ip_from_request(request),
|
65
|
+
headers: headers, url: url, http_method: method || '', body: body)
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SinatraContext
|
4
|
+
SECURENATIVE_COOKIE = '_sn'
|
5
|
+
|
6
|
+
def self.get_client_token(request)
|
7
|
+
begin
|
8
|
+
request.env[SECURENATIVE_COOKIE]
|
9
|
+
rescue StandardError
|
10
|
+
begin
|
11
|
+
request.cookies[SECURENATIVE_COOKIE]
|
12
|
+
rescue StandardError
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_url(request)
|
19
|
+
begin
|
20
|
+
request.env['REQUEST_URI']
|
21
|
+
rescue StandardError
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.get_method(request)
|
27
|
+
begin
|
28
|
+
request.env['REQUEST_METHOD']
|
29
|
+
rescue StandardError
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_headers(request)
|
35
|
+
begin
|
36
|
+
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
37
|
+
{ 'user-agent' => request.env['HTTP_USER_AGENT'] }
|
38
|
+
rescue StandardError
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EventTypes
|
4
|
+
LOG_IN = 'sn.user.login'
|
5
|
+
LOG_IN_CHALLENGE = 'sn.user.login.challenge'
|
6
|
+
LOG_IN_FAILURE = 'sn.user.login.failure'
|
7
|
+
LOG_OUT = 'sn.user.logout'
|
8
|
+
SIGN_UP = 'sn.user.signup'
|
9
|
+
AUTH_CHALLENGE = 'sn.user.auth.challenge'
|
10
|
+
AUTH_CHALLENGE_SUCCESS = 'sn.user.auth.challenge.success'
|
11
|
+
AUTH_CHALLENGE_FAILURE = 'sn.user.auth.challenge.failure'
|
12
|
+
TWO_FACTOR_DISABLE = 'sn.user.2fa.disable'
|
13
|
+
EMAIL_UPDATE = 'sn.user.email.update'
|
14
|
+
PASSWORD_REST = 'sn.user.password.reset'
|
15
|
+
PASSWORD_REST_SUCCESS = 'sn.user.password.reset.success'
|
16
|
+
PASSWORD_UPDATE = 'sn.user.password.update'
|
17
|
+
PASSWORD_REST_FAILURE = 'sn.user.password.reset.failure'
|
18
|
+
USER_INVITE = 'sn.user.invite'
|
19
|
+
ROLE_UPDATE = 'sn.user.role.update'
|
20
|
+
PROFILE_UPDATE = 'sn.user.profile.update'
|
21
|
+
PAGE_VIEW = 'sn.user.page.view'
|
22
|
+
VERIFY = 'sn.verify'
|
23
|
+
end
|