perimeter_x 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +11 -40
- data/changelog.md +9 -0
- data/lib/perimeterx/configuration.rb +3 -3
- data/lib/perimeterx/internal/clients/perimeter_x_activity_client.rb +4 -9
- data/lib/perimeterx/internal/validators/perimeter_x_captcha_validator.rb +1 -1
- data/lib/perimeterx/internal/validators/perimeter_x_s2s_validator.rb +5 -5
- data/lib/perimeterx/utils/px_http_client.rb +28 -34
- data/lib/perimeterx/version.rb +1 -1
- data/perimeter_x.gemspec +2 -1
- data/readme.md +2 -1
- metadata +33 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e3418c30763e225706ca5ee7a3a88958c4a210
|
4
|
+
data.tar.gz: 4671a1eb52edc4cfdb9ba4e85932c2dcb7e33dbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13ca73c6ac3c22ff0d9d93d42cab42049a06e458f9596538cd2225a07dd1ea9e20db8bf4c6921519ed29c349e717eb929643051ef1510337b1414bf6ea8f6c01
|
7
|
+
data.tar.gz: 2bc1a8fe0845f3899537bb34151c545ea7c6a5343b271c7bceb4d221a9551d74dec174042e30b02e7e29d533d7e0453235163ee0635d2275576c75ed4758efd5
|
data/Dockerfile
CHANGED
@@ -1,50 +1,21 @@
|
|
1
1
|
# Based on manual compile instructions at http://wiki.nginx.org/HttpLuaModule#Installation
|
2
|
-
FROM
|
3
|
-
RUN apt-get update && apt-get --force-yes -qq -y install \
|
4
|
-
build-essential \
|
5
|
-
ca-certificates \
|
6
|
-
curl \
|
7
|
-
git \
|
8
|
-
libpcre3 \
|
9
|
-
libpcre3-dev \
|
10
|
-
libssl-dev \
|
11
|
-
libreadline-dev \
|
12
|
-
libyaml-dev \
|
13
|
-
libgdbm-dev \
|
14
|
-
libtool \
|
15
|
-
automake \
|
16
|
-
bison \
|
17
|
-
lua-cjson \
|
18
|
-
libncurses5-dev \
|
19
|
-
m4 \
|
20
|
-
libsqlite3-dev \
|
21
|
-
rsyslog \
|
22
|
-
sqlite3 \
|
23
|
-
libxml2-dev \
|
24
|
-
libxslt1-dev \
|
25
|
-
libcurl4-openssl-dev \
|
26
|
-
python-software-properties \
|
27
|
-
libffi-dev \
|
28
|
-
nodejs \
|
29
|
-
wget \
|
30
|
-
zlib1g-dev
|
2
|
+
FROM ruby:2.3.0
|
31
3
|
|
32
|
-
RUN
|
33
|
-
|
34
|
-
|
35
|
-
RUN
|
36
|
-
RUN
|
37
|
-
RUN /bin/bash -l -c "gem install rails -v 4.2.0"
|
4
|
+
RUN apt-get update && apt-get --force-yes -qq -y install \
|
5
|
+
nodejs
|
6
|
+
ENV RAILS_VERSION 4.2.0
|
7
|
+
RUN gem install rails --version "$RAILS_VERSION"
|
8
|
+
RUN gem install bundler
|
38
9
|
RUN mkdir -p /tmp/ruby_sandbox
|
39
10
|
WORKDIR /tmp/ruby_sandbox
|
40
11
|
RUN git clone https://github.com/PerimeterX/perimeterx-ruby-sdk.git
|
41
|
-
RUN
|
12
|
+
RUN rails new webapp
|
42
13
|
WORKDIR /tmp/ruby_sandbox/webapp
|
43
|
-
|
14
|
+
|
15
|
+
RUN rails generate controller home index
|
44
16
|
WORKDIR /tmp/ruby_sandbox/webapp
|
45
17
|
EXPOSE 3000
|
46
|
-
# TODO: make it take the files from git
|
47
18
|
RUN sed -i '2i gem "perimeter_x", :path => "/tmp/ruby_sandbox/perimeterx-ruby-sdk"' /tmp/ruby_sandbox/webapp/Gemfile
|
48
|
-
RUN
|
19
|
+
RUN bundler update
|
49
20
|
COPY ./examples/ /tmp/ruby_sandbox/webapp
|
50
|
-
CMD ["
|
21
|
+
CMD ["rails","server","-b","0.0.0.0"]
|
data/changelog.md
CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
7
7
|
|
8
|
+
## [1.2.0] - 2017-06-04
|
9
|
+
### Fixed
|
10
|
+
- Default timeouts for post api requests
|
11
|
+
- Fixed Dockerfile
|
12
|
+
### Changed
|
13
|
+
- Removed httpclient and instead using typheous
|
14
|
+
### Added
|
15
|
+
- Using concurrent-ruby for async post requests
|
16
|
+
|
8
17
|
## [1.1.0] - 2017-06-04
|
9
18
|
### Added
|
10
19
|
- Added support for sensitive routes
|
@@ -17,9 +17,9 @@ module PxModule
|
|
17
17
|
:encryption_enabled => true,
|
18
18
|
:blocking_score => 70,
|
19
19
|
:sensitive_headers => ["http-cookie", "http-cookies"],
|
20
|
-
:api_connect_timeout =>
|
21
|
-
:api_timeout =>
|
22
|
-
:max_buffer_len =>
|
20
|
+
:api_connect_timeout => 1,
|
21
|
+
:api_timeout => 1,
|
22
|
+
:max_buffer_len => 10,
|
23
23
|
:send_page_activities => false,
|
24
24
|
:send_block_activities => true,
|
25
25
|
:sdk_name => PxModule::SDK_NAME,
|
@@ -3,12 +3,10 @@ require 'perimeterx/internal/clients/perimeter_x_risk_client'
|
|
3
3
|
module PxModule
|
4
4
|
class PerimeterxActivitiesClient < PerimeterxRiskClient
|
5
5
|
|
6
|
-
attr_accessor :activities
|
7
6
|
|
8
7
|
def initialize(px_config, http_client)
|
9
8
|
super(px_config, http_client)
|
10
9
|
@logger.debug("PerimeterxActivitiesClients[initialize]")
|
11
|
-
@activities = [];
|
12
10
|
end
|
13
11
|
|
14
12
|
def send_to_perimeterx(activity_type, px_ctx, details = [])
|
@@ -41,13 +39,10 @@ module PxModule
|
|
41
39
|
"Content-Type" => "application/json"
|
42
40
|
};
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@activities.clear
|
50
|
-
end
|
42
|
+
s = Time.now
|
43
|
+
@http_client.async.post(PxModule::API_V1_S2S, px_data, headers)
|
44
|
+
e = Time.now
|
45
|
+
@logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]: post runtime #{(e-s)*1000}")
|
51
46
|
end
|
52
47
|
|
53
48
|
def send_block_activity(px_ctx)
|
@@ -27,7 +27,7 @@ module PxModule
|
|
27
27
|
"Content-Type" => "application/json"
|
28
28
|
};
|
29
29
|
|
30
|
-
return @http_client.post(PxModule::API_V1_CAPTCHA, request_body, headers, @px_config[:api_timeout])
|
30
|
+
return @http_client.post(PxModule::API_V1_CAPTCHA, request_body, headers, @px_config[:api_timeout], @px_config[:api_timeout_connection])
|
31
31
|
|
32
32
|
end
|
33
33
|
|
@@ -67,9 +67,9 @@ module PxModule
|
|
67
67
|
|
68
68
|
# Custom risk handler
|
69
69
|
if (risk_mode == PxModule::ACTIVE_MODE && @px_config.key?(:custom_risk_handler))
|
70
|
-
response = @px_config[:custom_risk_handler].call(PxModule::API_V2_RISK, request_body, headers, @px_config[:api_timeout])
|
70
|
+
response = @px_config[:custom_risk_handler].call(PxModule::API_V2_RISK, request_body, headers, @px_config[:api_timeout], @px_config[:api_timeout_connection])
|
71
71
|
else
|
72
|
-
response = @http_client.post(PxModule::API_V2_RISK , request_body, headers)
|
72
|
+
response = @http_client.post(PxModule::API_V2_RISK , request_body, headers, @px_config[:api_timeout], @px_config[:api_timeout_connection])
|
73
73
|
end
|
74
74
|
return response
|
75
75
|
end
|
@@ -83,9 +83,9 @@ module PxModule
|
|
83
83
|
px_ctx.context[:made_s2s_risk_api_call] = true
|
84
84
|
|
85
85
|
# From here response should be valid, if success or error
|
86
|
-
response_body = eval(response.
|
86
|
+
response_body = eval(response.body);
|
87
87
|
# When success
|
88
|
-
if (response.
|
88
|
+
if (response.code == 200 && response_body.key?(:score) && response_body.key?(:action))
|
89
89
|
@logger.debug("PerimeterxS2SValidator[verify]: response ok")
|
90
90
|
score = response_body[:score]
|
91
91
|
px_ctx.context[:score] = score
|
@@ -100,7 +100,7 @@ module PxModule
|
|
100
100
|
end #end success response
|
101
101
|
|
102
102
|
# When error
|
103
|
-
if(response.
|
103
|
+
if(response.code != 200)
|
104
104
|
@logger.warn("PerimeterxS2SValidator[verify]: bad response, return code #{response.code}")
|
105
105
|
px_ctx.context[:uuid] = ""
|
106
106
|
px_ctx.context[:s2s_error_msg] = response_body[:message]
|
@@ -1,53 +1,47 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'perimeterx/utils/px_logger'
|
2
|
+
require 'typhoeus'
|
3
|
+
require 'concurrent'
|
3
4
|
|
4
5
|
module PxModule
|
5
6
|
class PxHttpClient
|
7
|
+
include Concurrent::Async
|
8
|
+
|
6
9
|
attr_accessor :px_config
|
7
|
-
attr_accessor :
|
8
|
-
attr_accessor :http_client
|
10
|
+
attr_accessor :px_client
|
9
11
|
|
10
12
|
def initialize(px_config)
|
11
13
|
@px_config = px_config
|
12
|
-
@http_client = HTTPClient.new(:base_url => px_config[:perimeterx_server_host])
|
13
14
|
@logger = px_config[:logger]
|
14
15
|
@logger.debug("PxHttpClient[initialize]: HTTP client is being initilized with base_uri: #{px_config[:perimeterx_server_host]}")
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
:timeout => api_timeout
|
25
|
-
)
|
26
|
-
rescue Net::OpenTimeout, Net::ReadTimeout => error
|
27
|
-
@logger.warn("PerimeterxS2SValidator[verify]: request timedout")
|
28
|
-
return false
|
29
|
-
end
|
30
|
-
e = Time.now
|
31
|
-
@logger.debug("PxHttpClient[post]: runtime: #{e-s}")
|
32
|
-
return response
|
33
|
-
end
|
18
|
+
# Runs a POST commant to Perimeter X servers
|
19
|
+
# Params:
|
20
|
+
# +path+:: string containing uri
|
21
|
+
# +body+:: hash object, containing the request body, must be converted to json format
|
22
|
+
# +headers+:: hash object, hold headers
|
23
|
+
# +api_timeout+:: int, sets the timeout for a request
|
24
|
+
# +connection_timeout+:: int, sets the timeout for opening a connection
|
34
25
|
|
35
|
-
def
|
36
|
-
@logger.debug("PxHttpClient[async_post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ")
|
26
|
+
def post(path, body, headers, api_timeout = 1, connection_timeout = 1)
|
37
27
|
s = Time.now
|
38
28
|
begin
|
39
29
|
@logger.debug("PxHttpClient[post]: posting to #{path} headers {#{headers.to_json()}} body: {#{body.to_json()}} ")
|
40
|
-
response =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
response = Typhoeus.post(
|
31
|
+
"#{px_config[:perimeterx_server_host]}#{path}",
|
32
|
+
headers: headers,
|
33
|
+
body: body.to_json,
|
34
|
+
timeout: api_timeout,
|
35
|
+
connecttimeout: connection_timeout
|
36
|
+
)
|
37
|
+
if response.timed_out?
|
38
|
+
@logger.warn('PerimeterxS2SValidator[verify]: request timed out')
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
e = Time.now
|
43
|
+
@logger.debug("PxHttpClient[post]: runtime: #{(e-s) * 1000.0}")
|
48
44
|
end
|
49
|
-
e = Time.now
|
50
|
-
@logger.debug("PxHttpClient[post]: runtime: #{e-s}")
|
51
45
|
return response
|
52
46
|
end
|
53
47
|
|
data/lib/perimeterx/version.rb
CHANGED
data/perimeter_x.gemspec
CHANGED
@@ -30,7 +30,8 @@ Gem::Specification.new do |gem|
|
|
30
30
|
|
31
31
|
gem.required_ruby_version = '>= 2.3'
|
32
32
|
|
33
|
-
gem.add_dependency('
|
33
|
+
gem.add_dependency('concurrent-ruby', '~> 1.0', '>= 1.0.5')
|
34
|
+
gem.add_dependency('typhoeus', '~> 1.1', '>= 1.1.2')
|
34
35
|
gem.add_dependency('mustache', '~> 1.0', '>= 1.0.3')
|
35
36
|
gem.add_dependency('activesupport', '>= 4.2.0')
|
36
37
|
|
data/readme.md
CHANGED
@@ -31,7 +31,8 @@ Table of Contents
|
|
31
31
|
|
32
32
|
- Ruby version 2.3+
|
33
33
|
- Rails version 4.2
|
34
|
-
- [
|
34
|
+
- [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby)
|
35
|
+
- [typhoeus](https://github.com/typhoeus/typhoeus)
|
35
36
|
- [mustache](https://rubygems.org/gems/mustache)
|
36
37
|
|
37
38
|
<a name="installation"></a> Installation
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perimeter_x
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nitzan Goldfeder
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,45 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: concurrent-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
50
|
+
version: 1.0.5
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- -
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.0.5
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: typhoeus
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.1'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.1.2
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.1'
|
78
|
+
- - ">="
|
53
79
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
80
|
+
version: 1.1.2
|
55
81
|
- !ruby/object:Gem::Dependency
|
56
82
|
name: mustache
|
57
83
|
requirement: !ruby/object:Gem::Requirement
|