securenative 0.1.23 → 0.1.29
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/README.md +43 -29
- data/lib/securenative.rb +47 -81
- data/{out/test/securenative-ruby → spec}/spec_helper.rb +0 -0
- metadata +8 -109
- data/.github/workflows/ci.yml +0 -49
- data/.github/workflows/publish.yml +0 -60
- data/.github/workflows/test.yml +0 -48
- data/.gitignore +0 -40
- data/.rakeTasks +0 -7
- data/.rspec +0 -3
- data/Gemfile +0 -11
- data/Gemfile.lock +0 -272
- data/LICENSE +0 -21
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/api_manager.rb +0 -39
- data/lib/config/configuration_builder.rb +0 -27
- data/lib/config/configuration_manager.rb +0 -56
- data/lib/config/securenative_options.rb +0 -23
- data/lib/context/hanami_context.rb +0 -42
- data/lib/context/rails_context.rb +0 -44
- data/lib/context/securenative_context.rb +0 -67
- data/lib/context/sinatra_context.rb +0 -42
- data/lib/enums/api_route.rb +0 -6
- data/lib/enums/event_types.rb +0 -23
- data/lib/enums/failover_strategy.rb +0 -6
- data/lib/enums/risk_level.rb +0 -7
- data/lib/errors/securenative_config_error.rb +0 -4
- data/lib/errors/securenative_http_error.rb +0 -4
- data/lib/errors/securenative_invalid_options_error.rb +0 -4
- data/lib/errors/securenative_invalid_uri_error.rb +0 -4
- data/lib/errors/securenative_parse_error.rb +0 -4
- data/lib/errors/securenative_sdk_Illegal_state_error.rb +0 -4
- data/lib/errors/securenative_sdk_error.rb +0 -4
- data/lib/event_manager.rb +0 -157
- data/lib/http/secure_native_http_response.rb +0 -12
- data/lib/http/securenative_http_client.rb +0 -50
- data/lib/models/client_token.rb +0 -12
- data/lib/models/device.rb +0 -10
- data/lib/models/event_options.rb +0 -37
- data/lib/models/request_context.rb +0 -18
- data/lib/models/request_options.rb +0 -12
- data/lib/models/sdk_event.rb +0 -49
- data/lib/models/user_traits.rb +0 -13
- data/lib/models/verify_result.rb +0 -16
- data/lib/utils/date_utils.rb +0 -9
- data/lib/utils/encryption_utils.rb +0 -49
- data/lib/utils/ip_utils.rb +0 -23
- data/lib/utils/request_utils.rb +0 -69
- data/lib/utils/secure_native_logger.rb +0 -44
- data/lib/utils/signature_utils.rb +0 -16
- data/lib/utils/utils.rb +0 -9
- data/lib/utils/version_utils.rb +0 -11
- data/out/production/securenative-ruby/api_manager.rb +0 -39
- data/out/production/securenative-ruby/config/configuration_builder.rb +0 -27
- data/out/production/securenative-ruby/config/configuration_manager.rb +0 -56
- data/out/production/securenative-ruby/config/securenative_options.rb +0 -23
- data/out/production/securenative-ruby/context/hanami_context.rb +0 -42
- data/out/production/securenative-ruby/context/rails_context.rb +0 -44
- data/out/production/securenative-ruby/context/securenative_context.rb +0 -67
- data/out/production/securenative-ruby/context/sinatra_context.rb +0 -42
- data/out/production/securenative-ruby/enums/api_route.rb +0 -6
- data/out/production/securenative-ruby/enums/event_types.rb +0 -23
- data/out/production/securenative-ruby/enums/failover_strategy.rb +0 -6
- data/out/production/securenative-ruby/enums/risk_level.rb +0 -7
- data/out/production/securenative-ruby/errors/securenative_config_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_http_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_invalid_options_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_sdk_error.rb +0 -4
- data/out/production/securenative-ruby/event_manager.rb +0 -157
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +0 -12
- data/out/production/securenative-ruby/http/securenative_http_client.rb +0 -50
- data/out/production/securenative-ruby/models/client_token.rb +0 -12
- data/out/production/securenative-ruby/models/device.rb +0 -10
- data/out/production/securenative-ruby/models/event_options.rb +0 -37
- data/out/production/securenative-ruby/models/request_context.rb +0 -18
- data/out/production/securenative-ruby/models/request_options.rb +0 -12
- data/out/production/securenative-ruby/models/sdk_event.rb +0 -49
- data/out/production/securenative-ruby/models/user_traits.rb +0 -13
- data/out/production/securenative-ruby/models/verify_result.rb +0 -16
- data/out/production/securenative-ruby/securenative.rb +0 -83
- data/out/production/securenative-ruby/utils/date_utils.rb +0 -9
- data/out/production/securenative-ruby/utils/encryption_utils.rb +0 -49
- data/out/production/securenative-ruby/utils/ip_utils.rb +0 -23
- data/out/production/securenative-ruby/utils/request_utils.rb +0 -69
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +0 -44
- data/out/production/securenative-ruby/utils/signature_utils.rb +0 -16
- data/out/production/securenative-ruby/utils/utils.rb +0 -9
- data/out/production/securenative-ruby/utils/version_utils.rb +0 -11
- data/out/test/securenative-ruby/spec_api_manager.rb +0 -87
- data/out/test/securenative-ruby/spec_context_builder.rb +0 -87
- data/out/test/securenative-ruby/spec_date_utils.rb +0 -13
- data/out/test/securenative-ruby/spec_encryption_utils.rb +0 -26
- data/out/test/securenative-ruby/spec_event_manager.rb +0 -93
- data/out/test/securenative-ruby/spec_ip_utils.rb +0 -41
- data/out/test/securenative-ruby/spec_request_utils.rb +0 -25
- data/out/test/securenative-ruby/spec_sdk_event.rb +0 -24
- data/out/test/securenative-ruby/spec_securenative.rb +0 -61
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +0 -31
- data/out/test/securenative-ruby/spec_signature_utils.rb +0 -18
- data/out/test/securenative-ruby/spec_version_util.rb +0 -10
- data/securenative.gemspec +0 -28
data/lib/utils/date_utils.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openssl'
|
4
|
-
require 'digest'
|
5
|
-
require 'base64'
|
6
|
-
require 'models/client_token'
|
7
|
-
|
8
|
-
class EncryptionUtils
|
9
|
-
def self.padding_key(key, length)
|
10
|
-
if key.length == length
|
11
|
-
key
|
12
|
-
else
|
13
|
-
if key.length > length
|
14
|
-
key.slice(0, length)
|
15
|
-
else
|
16
|
-
(length - key.length).times { key << '0' }
|
17
|
-
key
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.encrypt(plain_text, secret_key)
|
23
|
-
begin
|
24
|
-
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
25
|
-
cipher.encrypt
|
26
|
-
iv = cipher.random_iv
|
27
|
-
cipher.key = padding_key(secret_key, 32)
|
28
|
-
encrypted = cipher.update(plain_text) + cipher.final
|
29
|
-
(iv + encrypted).unpack1('H*')
|
30
|
-
rescue StandardError
|
31
|
-
''
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.decrypt(cipher_text, secret_key)
|
36
|
-
begin
|
37
|
-
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
38
|
-
cipher.decrypt
|
39
|
-
raw_data = [cipher_text].pack('H*')
|
40
|
-
cipher.iv = raw_data.slice(0, 16)
|
41
|
-
cipher.key = padding_key(secret_key, 32)
|
42
|
-
decrypted = JSON.parse(cipher.update(raw_data.slice(16, raw_data.length)) + cipher.final)
|
43
|
-
|
44
|
-
return ClientToken.new(decrypted['cid'], decrypted['vid'], decrypted['fp'])
|
45
|
-
rescue StandardError
|
46
|
-
ClientToken.new('', '','')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/utils/ip_utils.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "resolv"
|
4
|
-
|
5
|
-
class IpUtils
|
6
|
-
def self.ip_address?(ip_address)
|
7
|
-
return true if ip_address =~ Resolv::IPv4::Regex
|
8
|
-
return true if ip_address =~ Resolv::IPv6::Regex
|
9
|
-
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.valid_public_ip?(ip_address)
|
14
|
-
ip = IPAddr.new(ip_address)
|
15
|
-
return false if ip.loopback? || ip.private? || ip.link_local? || ip.untrusted? || ip.tainted?
|
16
|
-
|
17
|
-
true
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.loop_back?(ip_address)
|
21
|
-
IPAddr.new(ip_address).loopback?
|
22
|
-
end
|
23
|
-
end
|
data/lib/utils/request_utils.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class RequestUtils
|
4
|
-
SECURENATIVE_COOKIE = '_sn'
|
5
|
-
SECURENATIVE_HEADER = 'x-securenative'
|
6
|
-
|
7
|
-
def self.get_secure_header_from_request(headers)
|
8
|
-
begin
|
9
|
-
return headers[SECURENATIVE_HEADER] unless headers.nil?
|
10
|
-
rescue StandardError
|
11
|
-
[]
|
12
|
-
end
|
13
|
-
[]
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.get_client_ip_from_request(request, options = nil)
|
17
|
-
begin
|
18
|
-
return request.ip unless request.ip.nil?
|
19
|
-
rescue NoMethodError
|
20
|
-
end
|
21
|
-
|
22
|
-
begin
|
23
|
-
x_forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
|
24
|
-
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
25
|
-
rescue NoMethodError
|
26
|
-
begin
|
27
|
-
x_forwarded_for = request['HTTP_X_FORWARDED_FOR']
|
28
|
-
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
29
|
-
rescue NoMethodError
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
begin
|
34
|
-
x_forwarded_for = request.env['REMOTE_ADDR']
|
35
|
-
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
36
|
-
rescue NoMethodError
|
37
|
-
begin
|
38
|
-
x_forwarded_for = request['REMOTE_ADDR']
|
39
|
-
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
40
|
-
rescue NoMethodError
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
unless options.nil?
|
45
|
-
for header in options.proxy_headers do
|
46
|
-
begin
|
47
|
-
h = request.env[header]
|
48
|
-
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
49
|
-
rescue NoMethodError
|
50
|
-
begin
|
51
|
-
h = request[header]
|
52
|
-
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
53
|
-
rescue NoMethodError
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
''
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.get_remote_ip_from_request(request)
|
63
|
-
begin
|
64
|
-
request.remote_ip
|
65
|
-
rescue NoMethodError
|
66
|
-
''
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
class SecureNativeLogger
|
6
|
-
@logger = Logger.new(STDOUT)
|
7
|
-
|
8
|
-
def self.init_logger(level = 'DEBUG')
|
9
|
-
@logger.level = case level
|
10
|
-
when 'WARN'
|
11
|
-
Logger::WARN
|
12
|
-
when 'DEBUG'
|
13
|
-
Logger::DEBUG
|
14
|
-
when 'ERROR'
|
15
|
-
Logger::ERROR
|
16
|
-
when 'FATAL'
|
17
|
-
Logger::FATAL
|
18
|
-
when 'INFO'
|
19
|
-
Logger::INFO
|
20
|
-
else
|
21
|
-
Logger::FATAL
|
22
|
-
end
|
23
|
-
|
24
|
-
@logger.formatter = proc do |severity, datetime, progname, msg|
|
25
|
-
"[#{datetime}] #{severity} (#{progname}): #{msg}\n"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.info(msg)
|
30
|
-
@logger.info(msg)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.debug(msg)
|
34
|
-
@logger.debug(msg)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.warning(msg)
|
38
|
-
@logger.warning(msg)
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.error(msg)
|
42
|
-
@logger.error(msg)
|
43
|
-
end
|
44
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openssl'
|
4
|
-
|
5
|
-
class SignatureUtils
|
6
|
-
SIGNATURE_HEADER = 'x-securenative'
|
7
|
-
|
8
|
-
def self.valid_signature?(api_key, payload, header_signature)
|
9
|
-
key = api_key.encode('utf-8')
|
10
|
-
body = payload.encode('utf-8')
|
11
|
-
calculated_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), key, body)
|
12
|
-
calculated_signature.eql? header_signature
|
13
|
-
rescue StandardError
|
14
|
-
false
|
15
|
-
end
|
16
|
-
end
|
data/lib/utils/utils.rb
DELETED
data/lib/utils/version_utils.rb
DELETED
@@ -1,39 +0,0 @@
|
|
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
|
@@ -1,27 +0,0 @@
|
|
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
|
@@ -1,56 +0,0 @@
|
|
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
|
@@ -1,23 +0,0 @@
|
|
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
|
@@ -1,42 +0,0 @@
|
|
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
|
@@ -1,44 +0,0 @@
|
|
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
|