securenative 0.1.28 → 0.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +23 -32
- data/lib/securenative.rb +49 -0
- data/lib/securenative/api_manager.rb +10 -17
- data/lib/securenative/client.rb +79 -0
- data/lib/securenative/{models/client_token.rb → client_token.rb} +0 -0
- data/lib/securenative/config/configuration_builder.rb +22 -22
- data/lib/securenative/config/configuration_manager.rb +42 -43
- data/lib/securenative/context.rb +65 -0
- data/lib/securenative/{models/device.rb → device.rb} +0 -0
- data/lib/securenative/enums/api_route.rb +5 -3
- data/lib/securenative/enums/risk_level.rb +7 -5
- data/{out/production/securenative-ruby/errors/securenative_config_error.rb → lib/securenative/errors/config_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_http_error.rb → lib/securenative/errors/http_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_invalid_options_error.rb → lib/securenative/errors/invalid_options_error.rb} +0 -0
- data/lib/securenative/errors/{securenative_invalid_uri_error.rb → invalid_uri_error.rb} +0 -0
- data/lib/securenative/errors/{securenative_parse_error.rb → parse_error.rb} +0 -2
- data/{out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb → lib/securenative/errors/sdk_Illegal_state_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_sdk_error.rb → lib/securenative/errors/sdk_error.rb} +0 -0
- data/lib/securenative/event_manager.rb +125 -127
- data/lib/securenative/{models/event_options.rb → event_options.rb} +3 -7
- data/lib/securenative/{enums/event_types.rb → event_types.rb} +0 -0
- data/lib/securenative/{enums/failover_strategy.rb → failover_strategy.rb} +0 -0
- data/lib/securenative/frameworks/hanami.rb +46 -0
- data/lib/securenative/frameworks/rails.rb +48 -0
- data/lib/securenative/frameworks/sinatra.rb +46 -0
- data/lib/securenative/{http/securenative_http_client.rb → http_client.rb} +7 -12
- data/lib/securenative/{http/secure_native_http_response.rb → http_response.rb} +1 -1
- data/lib/securenative/{config/securenative_options.rb → options.rb} +1 -3
- data/lib/securenative/{models/request_context.rb → request_context.rb} +0 -0
- data/lib/securenative/{models/request_options.rb → request_options.rb} +0 -0
- data/lib/securenative/{models/sdk_event.rb → sdk_event.rb} +4 -11
- data/lib/securenative/{models/user_traits.rb → user_traits.rb} +0 -0
- data/lib/securenative/utils/date_utils.rb +6 -4
- data/lib/securenative/utils/encryption_utils.rb +34 -37
- data/lib/securenative/utils/ip_utils.rb +15 -15
- data/lib/securenative/utils/{secure_native_logger.rb → log.rb} +1 -1
- data/lib/securenative/utils/request_utils.rb +66 -47
- data/lib/securenative/utils/signature_utils.rb +12 -12
- data/lib/securenative/utils/utils.rb +6 -4
- data/lib/securenative/utils/version_utils.rb +9 -7
- data/lib/securenative/{models/verify_result.rb → verify_result.rb} +0 -0
- data/lib/securenative/{errors/securenative_sdk_error.rb → version.rb} +1 -2
- data/securenative.gemspec +5 -2
- data/{out/test/securenative-ruby → spec}/spec_helper.rb +0 -0
- metadata +35 -83
- data/lib/securenative/context/hanami_context.rb +0 -44
- data/lib/securenative/context/rails_context.rb +0 -46
- data/lib/securenative/context/securenative_context.rb +0 -69
- data/lib/securenative/context/sinatra_context.rb +0 -44
- data/lib/securenative/errors/securenative_config_error.rb +0 -6
- data/lib/securenative/errors/securenative_http_error.rb +0 -6
- data/lib/securenative/errors/securenative_invalid_options_error.rb +0 -6
- data/lib/securenative/errors/securenative_sdk_Illegal_state_error.rb +0 -6
- data/lib/securenative/sdk.rb +0 -85
- 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_invalid_uri_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_parse_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
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'openssl'
|
4
|
-
|
5
3
|
module SecureNative
|
6
|
-
|
7
|
-
|
4
|
+
module Utils
|
5
|
+
class SignatureUtils
|
6
|
+
SIGNATURE_HEADER = 'x-securenative'
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
16
|
end
|
17
17
|
end
|
18
|
-
end
|
18
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SecureNative
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Utils
|
5
|
+
class Utils
|
6
|
+
def self.null_or_empty?(string)
|
7
|
+
return true if !string || string.empty? || string.nil?
|
7
8
|
|
8
|
-
|
9
|
+
false
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SecureNative
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Utils
|
5
|
+
class VersionUtils
|
6
|
+
def self.version
|
7
|
+
begin
|
8
|
+
Gem.loaded_specs['securenative'].version.to_s
|
9
|
+
rescue StandardError
|
10
|
+
'unknown'
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
13
|
-
end
|
15
|
+
end
|
File without changes
|
data/securenative.gemspec
CHANGED
@@ -2,25 +2,28 @@
|
|
2
2
|
|
3
3
|
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
5
|
+
require 'securenative'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'securenative'
|
9
|
-
spec.version =
|
9
|
+
spec.version = SecureNative::VERSION
|
10
10
|
spec.authors = ['SecureNative']
|
11
11
|
spec.email = ['support@securenative.com']
|
12
|
+
spec.required_ruby_version = '>= 2.4'
|
12
13
|
|
13
14
|
spec.summary = 'SecureNative SDK for Ruby'
|
14
15
|
spec.homepage = 'https://www.securenative.com'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
17
18
|
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.test_files = Dir['spec//*']
|
18
20
|
|
19
21
|
# Specify which files should be added to the gem when it is released.
|
20
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
23
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
25
|
end
|
26
|
+
|
24
27
|
spec.bindir = 'exe'
|
25
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
29
|
spec.require_paths = ['lib']
|
File without changes
|
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.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SecureNative
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,98 +58,49 @@ files:
|
|
58
58
|
- Rakefile
|
59
59
|
- bin/console
|
60
60
|
- bin/setup
|
61
|
+
- lib/securenative.rb
|
61
62
|
- lib/securenative/api_manager.rb
|
63
|
+
- lib/securenative/client.rb
|
64
|
+
- lib/securenative/client_token.rb
|
62
65
|
- lib/securenative/config/configuration_builder.rb
|
63
66
|
- lib/securenative/config/configuration_manager.rb
|
64
|
-
- lib/securenative/
|
65
|
-
- lib/securenative/
|
66
|
-
- lib/securenative/context/rails_context.rb
|
67
|
-
- lib/securenative/context/securenative_context.rb
|
68
|
-
- lib/securenative/context/sinatra_context.rb
|
67
|
+
- lib/securenative/context.rb
|
68
|
+
- lib/securenative/device.rb
|
69
69
|
- lib/securenative/enums/api_route.rb
|
70
|
-
- lib/securenative/enums/event_types.rb
|
71
|
-
- lib/securenative/enums/failover_strategy.rb
|
72
70
|
- lib/securenative/enums/risk_level.rb
|
73
|
-
- lib/securenative/errors/
|
74
|
-
- lib/securenative/errors/
|
75
|
-
- lib/securenative/errors/
|
76
|
-
- lib/securenative/errors/
|
77
|
-
- lib/securenative/errors/
|
78
|
-
- lib/securenative/errors/
|
79
|
-
- lib/securenative/errors/
|
71
|
+
- lib/securenative/errors/config_error.rb
|
72
|
+
- lib/securenative/errors/http_error.rb
|
73
|
+
- lib/securenative/errors/invalid_options_error.rb
|
74
|
+
- lib/securenative/errors/invalid_uri_error.rb
|
75
|
+
- lib/securenative/errors/parse_error.rb
|
76
|
+
- lib/securenative/errors/sdk_Illegal_state_error.rb
|
77
|
+
- lib/securenative/errors/sdk_error.rb
|
80
78
|
- lib/securenative/event_manager.rb
|
81
|
-
- lib/securenative/
|
82
|
-
- lib/securenative/
|
83
|
-
- lib/securenative/
|
84
|
-
- lib/securenative/
|
85
|
-
- lib/securenative/
|
86
|
-
- lib/securenative/
|
87
|
-
- lib/securenative/
|
88
|
-
- lib/securenative/
|
89
|
-
- lib/securenative/
|
90
|
-
- lib/securenative/
|
91
|
-
- lib/securenative/
|
79
|
+
- lib/securenative/event_options.rb
|
80
|
+
- lib/securenative/event_types.rb
|
81
|
+
- lib/securenative/failover_strategy.rb
|
82
|
+
- lib/securenative/frameworks/hanami.rb
|
83
|
+
- lib/securenative/frameworks/rails.rb
|
84
|
+
- lib/securenative/frameworks/sinatra.rb
|
85
|
+
- lib/securenative/http_client.rb
|
86
|
+
- lib/securenative/http_response.rb
|
87
|
+
- lib/securenative/options.rb
|
88
|
+
- lib/securenative/request_context.rb
|
89
|
+
- lib/securenative/request_options.rb
|
90
|
+
- lib/securenative/sdk_event.rb
|
91
|
+
- lib/securenative/user_traits.rb
|
92
92
|
- lib/securenative/utils/date_utils.rb
|
93
93
|
- lib/securenative/utils/encryption_utils.rb
|
94
94
|
- lib/securenative/utils/ip_utils.rb
|
95
|
+
- lib/securenative/utils/log.rb
|
95
96
|
- lib/securenative/utils/request_utils.rb
|
96
|
-
- lib/securenative/utils/secure_native_logger.rb
|
97
97
|
- lib/securenative/utils/signature_utils.rb
|
98
98
|
- lib/securenative/utils/utils.rb
|
99
99
|
- lib/securenative/utils/version_utils.rb
|
100
|
-
-
|
101
|
-
-
|
102
|
-
- out/production/securenative-ruby/config/configuration_manager.rb
|
103
|
-
- out/production/securenative-ruby/config/securenative_options.rb
|
104
|
-
- out/production/securenative-ruby/context/hanami_context.rb
|
105
|
-
- out/production/securenative-ruby/context/rails_context.rb
|
106
|
-
- out/production/securenative-ruby/context/securenative_context.rb
|
107
|
-
- out/production/securenative-ruby/context/sinatra_context.rb
|
108
|
-
- out/production/securenative-ruby/enums/api_route.rb
|
109
|
-
- out/production/securenative-ruby/enums/event_types.rb
|
110
|
-
- out/production/securenative-ruby/enums/failover_strategy.rb
|
111
|
-
- out/production/securenative-ruby/enums/risk_level.rb
|
112
|
-
- out/production/securenative-ruby/errors/securenative_config_error.rb
|
113
|
-
- out/production/securenative-ruby/errors/securenative_http_error.rb
|
114
|
-
- out/production/securenative-ruby/errors/securenative_invalid_options_error.rb
|
115
|
-
- out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb
|
116
|
-
- out/production/securenative-ruby/errors/securenative_parse_error.rb
|
117
|
-
- out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb
|
118
|
-
- out/production/securenative-ruby/errors/securenative_sdk_error.rb
|
119
|
-
- out/production/securenative-ruby/event_manager.rb
|
120
|
-
- out/production/securenative-ruby/http/secure_native_http_response.rb
|
121
|
-
- out/production/securenative-ruby/http/securenative_http_client.rb
|
122
|
-
- out/production/securenative-ruby/models/client_token.rb
|
123
|
-
- out/production/securenative-ruby/models/device.rb
|
124
|
-
- out/production/securenative-ruby/models/event_options.rb
|
125
|
-
- out/production/securenative-ruby/models/request_context.rb
|
126
|
-
- out/production/securenative-ruby/models/request_options.rb
|
127
|
-
- out/production/securenative-ruby/models/sdk_event.rb
|
128
|
-
- out/production/securenative-ruby/models/user_traits.rb
|
129
|
-
- out/production/securenative-ruby/models/verify_result.rb
|
130
|
-
- out/production/securenative-ruby/securenative.rb
|
131
|
-
- out/production/securenative-ruby/utils/date_utils.rb
|
132
|
-
- out/production/securenative-ruby/utils/encryption_utils.rb
|
133
|
-
- out/production/securenative-ruby/utils/ip_utils.rb
|
134
|
-
- out/production/securenative-ruby/utils/request_utils.rb
|
135
|
-
- out/production/securenative-ruby/utils/secure_native_logger.rb
|
136
|
-
- out/production/securenative-ruby/utils/signature_utils.rb
|
137
|
-
- out/production/securenative-ruby/utils/utils.rb
|
138
|
-
- out/production/securenative-ruby/utils/version_utils.rb
|
139
|
-
- out/test/securenative-ruby/spec_api_manager.rb
|
140
|
-
- out/test/securenative-ruby/spec_context_builder.rb
|
141
|
-
- out/test/securenative-ruby/spec_date_utils.rb
|
142
|
-
- out/test/securenative-ruby/spec_encryption_utils.rb
|
143
|
-
- out/test/securenative-ruby/spec_event_manager.rb
|
144
|
-
- out/test/securenative-ruby/spec_helper.rb
|
145
|
-
- out/test/securenative-ruby/spec_ip_utils.rb
|
146
|
-
- out/test/securenative-ruby/spec_request_utils.rb
|
147
|
-
- out/test/securenative-ruby/spec_sdk_event.rb
|
148
|
-
- out/test/securenative-ruby/spec_securenative.rb
|
149
|
-
- out/test/securenative-ruby/spec_securenative_http_client.rb
|
150
|
-
- out/test/securenative-ruby/spec_signature_utils.rb
|
151
|
-
- out/test/securenative-ruby/spec_version_util.rb
|
100
|
+
- lib/securenative/verify_result.rb
|
101
|
+
- lib/securenative/version.rb
|
152
102
|
- securenative.gemspec
|
103
|
+
- spec//spec_helper.rb
|
153
104
|
homepage: https://www.securenative.com
|
154
105
|
licenses:
|
155
106
|
- MIT
|
@@ -163,15 +114,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
114
|
requirements:
|
164
115
|
- - ">="
|
165
116
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
117
|
+
version: '2.4'
|
167
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
119
|
requirements:
|
169
120
|
- - ">="
|
170
121
|
- !ruby/object:Gem::Version
|
171
122
|
version: '0'
|
172
123
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
124
|
+
rubygems_version: 3.1.2
|
174
125
|
signing_key:
|
175
126
|
specification_version: 4
|
176
127
|
summary: SecureNative SDK for Ruby
|
177
|
-
test_files:
|
128
|
+
test_files:
|
129
|
+
- spec//spec_helper.rb
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SecureNative
|
4
|
-
class HanamiContext
|
5
|
-
SECURENATIVE_COOKIE = '_sn'
|
6
|
-
|
7
|
-
def self.get_client_token(request)
|
8
|
-
begin
|
9
|
-
request.env[SECURENATIVE_COOKIE]
|
10
|
-
rescue StandardError
|
11
|
-
begin
|
12
|
-
request.cookies[SECURENATIVE_COOKIE]
|
13
|
-
rescue StandardError
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.get_url(request)
|
20
|
-
begin
|
21
|
-
request.env['REQUEST_PATH']
|
22
|
-
rescue StandardError
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.get_method(request)
|
28
|
-
begin
|
29
|
-
request.request_method
|
30
|
-
rescue StandardError
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.get_headers(request)
|
36
|
-
begin
|
37
|
-
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
38
|
-
{ 'user-agent' => request.env['HTTP_USER_AGENT'] }
|
39
|
-
rescue StandardError
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SecureNative
|
4
|
-
class RailsContext
|
5
|
-
SECURENATIVE_COOKIE = '_sn'
|
6
|
-
|
7
|
-
def self.get_client_token(request)
|
8
|
-
begin
|
9
|
-
request.cookies[SECURENATIVE_COOKIE]
|
10
|
-
rescue StandardError
|
11
|
-
nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.get_url(request)
|
16
|
-
begin
|
17
|
-
# Rails >= 3.x
|
18
|
-
request.fullpath
|
19
|
-
rescue StandardError
|
20
|
-
begin
|
21
|
-
# Rails < 3.x & Sinatra
|
22
|
-
request.url if url.nil?
|
23
|
-
rescue StandardError
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.get_method(request)
|
30
|
-
begin
|
31
|
-
request.method
|
32
|
-
rescue StandardError
|
33
|
-
nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.get_headers(request)
|
38
|
-
begin
|
39
|
-
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
40
|
-
{'user-agent' => request.env['HTTP_USER_AGENT']}
|
41
|
-
rescue StandardError
|
42
|
-
nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securenative/utils/request_utils'
|
4
|
-
require 'securenative/utils/utils'
|
5
|
-
require 'securenative/context/rails_context'
|
6
|
-
require 'securenative/context/hanami_context'
|
7
|
-
require 'securenative/context/sinatra_context'
|
8
|
-
|
9
|
-
module SecureNative
|
10
|
-
class SecureNativeContext
|
11
|
-
attr_reader :client_token, :ip, :remote_ip, :headers, :url, :http_method, :body
|
12
|
-
attr_writer :client_token, :ip, :remote_ip, :headers, :url, :http_method, :body
|
13
|
-
|
14
|
-
SECURENATIVE_COOKIE = '_sn'
|
15
|
-
|
16
|
-
def initialize(client_token: '', ip: '', remote_ip: '', headers: nil, url: '', http_method: '', body: '')
|
17
|
-
@client_token = client_token
|
18
|
-
@ip = ip
|
19
|
-
@remote_ip = remote_ip
|
20
|
-
@headers = headers
|
21
|
-
@url = url
|
22
|
-
@http_method = http_method
|
23
|
-
@body = body
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.default_context_builder
|
27
|
-
SecureNativeContext.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.from_http_request(request)
|
31
|
-
client_token = RailsContext.get_client_token(request)
|
32
|
-
client_token = SinatraContext.get_client_token(request) if client_token.nil?
|
33
|
-
client_token = HanamiContext.get_client_token(request) if client_token.nil?
|
34
|
-
|
35
|
-
begin
|
36
|
-
headers = RailsContext.get_headers(request)
|
37
|
-
headers = SinatraContext.get_headers(request) if headers.nil?
|
38
|
-
headers = HanamiContext.get_headers(request) if headers.nil?
|
39
|
-
|
40
|
-
# Standard Ruby request
|
41
|
-
headers = request.header.to_hash if headers.nil?
|
42
|
-
rescue StandardError
|
43
|
-
headers = []
|
44
|
-
end
|
45
|
-
|
46
|
-
url = RailsContext.get_url(request)
|
47
|
-
url = SinatraContext.get_url(request) if url.nil?
|
48
|
-
url = HanamiContext.get_url(request) if url.nil?
|
49
|
-
url = '' if url.nil?
|
50
|
-
|
51
|
-
method = RailsContext.get_method(request)
|
52
|
-
method = SinatraContext.get_method(request) if method.nil?
|
53
|
-
method = HanamiContext.get_method(request) if method.nil?
|
54
|
-
method = '' if method.nil?
|
55
|
-
|
56
|
-
begin
|
57
|
-
body = request.body.to_s
|
58
|
-
rescue StandardError
|
59
|
-
body = ''
|
60
|
-
end
|
61
|
-
|
62
|
-
client_token = RequestUtils.get_secure_header_from_request(headers) if Utils.null_or_empty?(client_token)
|
63
|
-
|
64
|
-
SecureNativeContext.new(client_token: client_token, ip: RequestUtils.get_client_ip_from_request(request),
|
65
|
-
remote_ip: RequestUtils.get_remote_ip_from_request(request),
|
66
|
-
headers: headers, url: url, http_method: method || '', body: body)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SecureNative
|
4
|
-
class SinatraContext
|
5
|
-
SECURENATIVE_COOKIE = '_sn'
|
6
|
-
|
7
|
-
def self.get_client_token(request)
|
8
|
-
begin
|
9
|
-
request.env[SECURENATIVE_COOKIE]
|
10
|
-
rescue StandardError
|
11
|
-
begin
|
12
|
-
request.cookies[SECURENATIVE_COOKIE]
|
13
|
-
rescue StandardError
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.get_url(request)
|
20
|
-
begin
|
21
|
-
request.env['REQUEST_URI']
|
22
|
-
rescue StandardError
|
23
|
-
nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.get_method(request)
|
28
|
-
begin
|
29
|
-
request.env['REQUEST_METHOD']
|
30
|
-
rescue StandardError
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.get_headers(request)
|
36
|
-
begin
|
37
|
-
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
38
|
-
{'user-agent' => request.env['HTTP_USER_AGENT']}
|
39
|
-
rescue StandardError
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|