Skip to content

Commit 92f0f75

Browse files
authored
Merge pull request #72 from PerimeterX/release/v2.3.2
Release/v2.3.2
2 parents 1f183ef + 9418538 commit 92f0f75

14 files changed

+57
-51
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ examples/app/views/home/index.html.erb
1717
*.gem
1818
rerun.txt
1919
pickle-email-*.html
20+
.idea/
21+
.vscode/
2022

2123
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
2224
config/initializers/secret_token.rb

Gemfile.lock

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
PATH
22
remote: .
33
specs:
4-
perimeter_x (2.0.0)
5-
activesupport (>= 5.2.4.3)
4+
perimeter_x (2.3.1)
65
concurrent-ruby (~> 1.0, >= 1.0.5)
76
mustache (~> 1.0, >= 1.0.3)
87
typhoeus (~> 1.1, >= 1.1.2)
98

109
GEM
1110
remote: https://rubygems.org/
1211
specs:
13-
activesupport (6.0.3.2)
14-
concurrent-ruby (~> 1.0, >= 1.0.2)
15-
i18n (>= 0.7, < 2)
16-
minitest (~> 5.1)
17-
tzinfo (~> 1.1)
18-
zeitwerk (~> 2.2, >= 2.2.2)
19-
concurrent-ruby (1.1.6)
12+
concurrent-ruby (1.1.10)
2013
diff-lcs (1.4.4)
21-
ethon (0.12.0)
22-
ffi (>= 1.3.0)
23-
ffi (1.13.1)
24-
i18n (1.8.3)
25-
concurrent-ruby (~> 1.0)
26-
minitest (5.14.1)
14+
ethon (0.15.0)
15+
ffi (>= 1.15.0)
16+
ffi (1.15.5)
2717
mocha (1.11.2)
2818
mustache (1.1.1)
2919
rake (13.0.1)
@@ -40,12 +30,8 @@ GEM
4030
diff-lcs (>= 1.2.0, < 2.0)
4131
rspec-support (~> 3.9.0)
4232
rspec-support (3.9.3)
43-
thread_safe (0.3.6)
4433
typhoeus (1.4.0)
4534
ethon (>= 0.9.0)
46-
tzinfo (1.2.7)
47-
thread_safe (~> 0.1)
48-
zeitwerk (2.3.1)
4935

5036
PLATFORMS
5137
ruby

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [2.3.2] - 2022-xx-xx
9+
10+
### Changed
11+
12+
- Removed dependency on Active Support
13+
- Replaced `eval()` calls with `JSON.parse()` for improved security
14+
- Small spec alignment changes (risk_api and block activities)
15+
816
## [2.3.1] - 2022-04-11
917

1018
### Fixed

lib/perimeterx/configuration.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def initialize(params)
8282
# merge request configuration into the basic configuration
8383
@configuration = @@basic_config.merge(params)
8484
validate_hash_schema(@configuration, CONFIG_SCHEMA)
85-
86-
@configuration[:backend_url] = "https://sapi-#{@configuration[:app_id].downcase}.perimeterx.net"
85+
86+
if (! @configuration.key?(:backend_url))
87+
@configuration[:backend_url] = "https://sapi-#{@configuration[:app_id].downcase}.perimeterx.net"
88+
end
8789
@configuration[:logger] = PxLogger.new(@configuration[:debug])
8890
end
8991
end

lib/perimeterx/internal/clients/perimeter_x_activity_client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def send_block_activity(px_ctx)
6363
:client_uuid => px_ctx.context[:uuid],
6464
:block_score => px_ctx.context[:score],
6565
:block_reason => px_ctx.context[:blocking_reason],
66+
:block_action => px_ctx.context[:block_action],
6667
:simulated_block => @px_config[:module_mode] == PxModule::MONITOR_MODE
6768
}
6869

lib/perimeterx/internal/payload/perimeter_x_cookie_v3.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def cookie_hmac
2222
end
2323

2424
def valid_format?(cookie)
25-
return cookie.key?(:t) && cookie.key?(:s) && cookie.key?(:u) && cookie.key?(:u) && cookie.key?(:a)
25+
return cookie.key?(:t) && cookie.key?(:s) && cookie.key?(:u) && cookie.key?(:a)
2626
end
2727

2828
def cookie_block_action

lib/perimeterx/internal/payload/perimeter_x_payload.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require 'active_support/security_utils'
21
require 'base64'
32
require 'openssl'
3+
require 'json'
44
require 'perimeterx/internal/exceptions/px_cookie_decryption_exception'
55

66
module PxModule
@@ -123,26 +123,34 @@ def decrypt(px_cookie)
123123
cipher.iv = iv
124124
plaintext = cipher.update(cipher_text) + cipher.final
125125

126-
return eval(plaintext)
126+
return JSON.parse(plaintext, symbolize_names: true)
127127
rescue Exception => e
128128
@logger.debug("PerimeterxCookie[decrypt]: Cookie decrypt fail #{e.message}")
129129
raise PxCookieDecryptionException.new("Cookie decrypt fail => #{e.message}");
130130
end
131131
end
132132

133133
def decode(px_cookie)
134-
return eval(Base64.decode64(px_cookie))
134+
return JSON.parse(Base64.decode64(px_cookie), symbolize_names: true)
135135
end
136136

137137

138138
def hmac_valid?(hmac_str, cookie_hmac)
139139
hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, @cookie_secret, hmac_str)
140-
# ref: https://thisdata.com/blog/timing-attacks-against-string-comparison/
141-
password_correct = ActiveSupport::SecurityUtils.secure_compare(
142-
::Digest::SHA256.hexdigest(cookie_hmac),
143-
::Digest::SHA256.hexdigest(hmac)
144-
)
140+
password_correct = secure_compare(hmac, cookie_hmac)
141+
end
142+
143+
def secure_compare(a, b)
144+
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/security_utils.rb
145+
if (a.bytesize != b.bytesize)
146+
return false
147+
end
148+
149+
l = a.unpack "C#{a.bytesize}"
145150

151+
res = 0
152+
b.each_byte { |byte| res |= byte ^ l.shift }
153+
res == 0
146154
end
147155
end
148156
end

lib/perimeterx/internal/perimeter_x_context.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,25 @@ def initialize(px_config, req)
101101
@context[:sensitive_route] = check_sensitive_route(px_config[:sensitive_routes], @context[:uri])
102102
end #end init
103103

104-
def check_sensitive_route(sensitive_routes, uri)
105-
sensitive_routes.each do |sensitive_route|
106-
return true if uri.start_with? sensitive_route
107-
end
108-
false
109-
end
104+
def check_sensitive_route(sensitive_routes, uri)
105+
sensitive_routes.each do |sensitive_route|
106+
return true if uri.start_with? sensitive_route
107+
end
108+
false
109+
end
110110

111111
def set_block_action_type(action)
112112
@context[:block_action] = case action
113113
when 'c'
114-
'captcha'
114+
return 'captcha'
115115
when 'b'
116116
return 'block'
117117
when 'j'
118118
return 'challenge'
119119
when 'r'
120120
return 'rate_limit'
121121
else
122-
return captcha
122+
return 'captcha'
123123
end
124124
end
125125

lib/perimeterx/internal/validators/perimeter_x_s2s_validator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'json'
12
require 'perimeterx/internal/clients/perimeter_x_risk_client'
23

34
module PxModule
@@ -20,7 +21,6 @@ def send_risk_request(px_ctx)
2021
:request => {
2122
:ip => px_ctx.context[:ip],
2223
:headers => format_headers(px_ctx),
23-
:uri => px_ctx.context[:uri],
2424
:url => px_ctx.context[:full_url]
2525
},
2626
:additional => {
@@ -103,7 +103,7 @@ def verify(px_ctx)
103103
px_ctx.context[:made_s2s_risk_api_call] = true
104104

105105
# From here response should be valid, if success or error
106-
response_body = eval(response.body);
106+
response_body = JSON.parse(response.body, symbolize_names: true);
107107
# When success
108108
if (response.code == 200 && response_body.key?(:score) && response_body.key?(:action) && response_body.key?(:status) && response_body[:status] == 0 )
109109
@logger.debug("PerimeterxS2SValidator[verify]: response ok")

lib/perimeterx/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module PxModule
2-
VERSION = '2.3.1'
2+
VERSION = '2.3.2'
33
end

0 commit comments

Comments
 (0)