perimeter_x 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +47 -0
  3. data/Dockerfile +50 -0
  4. data/Gemfile +3 -0
  5. data/Gemfile.lock +55 -0
  6. data/LICENSE.txt +18 -0
  7. data/Rakefile +9 -0
  8. data/changelog.md +0 -0
  9. data/examples/app/controllers/home_controller.rb +9 -0
  10. data/examples/app/views/home/index.html.erb.dist +20 -0
  11. data/examples/config/initializers/perimeterx.rb.dist +8 -0
  12. data/examples/config/routes.rb +62 -0
  13. data/lib/perimeter_x.rb +149 -0
  14. data/lib/perimeterx/configuration.rb +37 -0
  15. data/lib/perimeterx/internal/clients/perimeter_x_activity_client.rb +92 -0
  16. data/lib/perimeterx/internal/clients/perimeter_x_risk_client.rb +28 -0
  17. data/lib/perimeterx/internal/exceptions/px_cookie_decryption_exception.rb +5 -0
  18. data/lib/perimeterx/internal/perimeter_x_context.rb +82 -0
  19. data/lib/perimeterx/internal/perimeter_x_cookie.rb +140 -0
  20. data/lib/perimeterx/internal/perimeter_x_cookie_v1.rb +42 -0
  21. data/lib/perimeterx/internal/perimeter_x_cookie_v3.rb +37 -0
  22. data/lib/perimeterx/internal/validators/perimeter_x_captcha_validator.rb +65 -0
  23. data/lib/perimeterx/internal/validators/perimeter_x_cookie_validator.rb +69 -0
  24. data/lib/perimeterx/internal/validators/perimeter_x_s2s_validator.rb +110 -0
  25. data/lib/perimeterx/utils/px_constants.rb +42 -0
  26. data/lib/perimeterx/utils/px_http_client.rb +55 -0
  27. data/lib/perimeterx/utils/px_logger.rb +17 -0
  28. data/lib/perimeterx/utils/px_template_factory.rb +31 -0
  29. data/lib/perimeterx/utils/templates/block.mustache +146 -0
  30. data/lib/perimeterx/utils/templates/captcha.mustache +185 -0
  31. data/lib/perimeterx/version.rb +3 -0
  32. data/perimeter_x.gemspec +39 -0
  33. data/readme.md +294 -0
  34. metadata +192 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e61d04b45a194ff17fd78a20e69daaf0816f105c
4
+ data.tar.gz: 7adfcc853eb8b8f17957e0103157ff96c00f80e5
5
+ SHA512:
6
+ metadata.gz: 680ae56d9caa2be50863b3e4cecf0cb34d2f4f1702437e8853344f279068f659d8ef19a7077924f00ce90be3a8ba49fe2491f6df0b6d102544ab7c602801890f
7
+ data.tar.gz: 4016e3c1ad702745335ff15bd2987ee0120db8579ede2ad6b23c165e98bec303413033260e521b53792d37bad3af4bd425a148fad275ff3657a16f6f06c210ef
data/.gitignore ADDED
@@ -0,0 +1,47 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /log
5
+ /tmp
6
+ /bin
7
+ /dev
8
+ /db/*.sqlite3
9
+ /db/*.sqlite3-journal
10
+ /public/system
11
+ /coverage/
12
+ /spec/tmp
13
+ examples/config/initializers/perimeterx.rb
14
+ examples/app/views/home/index.html.erb
15
+ **.orig
16
+ *.gem
17
+ rerun.txt
18
+ pickle-email-*.html
19
+
20
+ # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
21
+ config/initializers/secret_token.rb
22
+ config/secrets.yml
23
+
24
+ # dotenv
25
+ # TODO Comment out this rule if environment variables can be committed
26
+ .env
27
+
28
+ ## Environment normalization:
29
+ /.bundle
30
+ /vendor/bundle
31
+
32
+ # these should all be checked in to normalize the environment:
33
+ # Gemfile.lock, .ruby-version, .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
37
+
38
+ # if using bower-rails ignore default bower_components path bower.json files
39
+ /vendor/assets/bower_components
40
+ *.bowerrc
41
+ bower.json
42
+
43
+ # Ignore pow environment settings
44
+ .powenv
45
+
46
+ # Ignore Byebug command history file.
47
+ .byebug_history
data/Dockerfile ADDED
@@ -0,0 +1,50 @@
1
+ # Based on manual compile instructions at http://wiki.nginx.org/HttpLuaModule#Installation
2
+ FROM ubuntu:14.04
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
31
+
32
+ RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
33
+ RUN /bin/bash -l -c "curl -L get.rvm.io | bash -s stable --rails"
34
+ RUN /bin/bash -l -c "rvm install 2.3.0"
35
+ RUN /bin/bash -l -c "rvm use 2.3.0"
36
+ RUN /bin/bash -l -c "gem install bundler"
37
+ RUN /bin/bash -l -c "gem install rails -v 4.2.0"
38
+ RUN mkdir -p /tmp/ruby_sandbox
39
+ WORKDIR /tmp/ruby_sandbox
40
+ RUN git clone https://github.com/PerimeterX/perimeterx-ruby-sdk.git
41
+ RUN /bin/bash -l -c "rails new webapp"
42
+ WORKDIR /tmp/ruby_sandbox/webapp
43
+ RUN /bin/bash -l -c "rails generate controller home index"
44
+ WORKDIR /tmp/ruby_sandbox/webapp
45
+ EXPOSE 3000
46
+ # TODO: make it take the files from git
47
+ RUN sed -i '2i gem "perimeter_x", :path => "/tmp/ruby_sandbox/perimeterx-ruby-sdk"' /tmp/ruby_sandbox/webapp/Gemfile
48
+ RUN /bin/bash -l -c "bundler update"
49
+ COPY ./examples/ /tmp/ruby_sandbox/webapp
50
+ CMD ["/bin/bash", "-l", "-c", "rails server -b 0.0.0.0;"]
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ perimeter_x (1.0.0)
5
+ activesupport (>= 4.2.0)
6
+ httpclient (= 2.8.2.4)
7
+ mustache (~> 1.0, >= 1.0.3)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.0.2)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (~> 0.7)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ concurrent-ruby (1.0.5)
18
+ diff-lcs (1.3)
19
+ httpclient (2.8.2.4)
20
+ i18n (0.8.1)
21
+ metaclass (0.0.4)
22
+ minitest (5.10.1)
23
+ mocha (1.2.1)
24
+ metaclass (~> 0.0.1)
25
+ mustache (1.0.4)
26
+ rake (10.4.2)
27
+ rspec (3.5.0)
28
+ rspec-core (~> 3.5.0)
29
+ rspec-expectations (~> 3.5.0)
30
+ rspec-mocks (~> 3.5.0)
31
+ rspec-core (3.5.4)
32
+ rspec-support (~> 3.5.0)
33
+ rspec-expectations (3.5.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.5.0)
36
+ rspec-mocks (3.5.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.5.0)
39
+ rspec-support (3.5.0)
40
+ thread_safe (0.3.6)
41
+ tzinfo (1.2.3)
42
+ thread_safe (~> 0.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.14)
49
+ mocha (~> 1.2, >= 1.2.1)
50
+ perimeter_x!
51
+ rake (~> 10.0)
52
+ rspec (~> 3.0)
53
+
54
+ BUNDLED WITH
55
+ 1.14.6
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ Copyright © 2016 PerimeterX, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
14
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
17
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+ rescue LoadError
8
+ # no rspec available
9
+ end
data/changelog.md ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ class HomeController < ApplicationController
2
+ include PxModule
3
+
4
+ before_filter :px_verify_request
5
+
6
+ def index
7
+ end
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ <h1>Home#index</h1>
2
+ <p>Find me in app/views/home/index.html.erb</p>
3
+
4
+ <script type="text/javascript">
5
+ (function(){
6
+ window._pxAppId ='APP_ID';
7
+ // Custom parameters
8
+ // window._pxParam1 = "<param1>";
9
+ var p = document.getElementsByTagName('script')[0],
10
+ s = document.createElement('script');
11
+ s.async = 1;
12
+ s.src = '//client.perimeterx.net/APP_ID/main.min.js';
13
+ p.parentNode.insertBefore(s,p);
14
+ }());
15
+ </script>
16
+ <noscript>
17
+ <div style="position:fixed; top:0; left:0; display:none" width="1" height="1">
18
+ <img src="//collector-APP_ID.perimeterx.net/api/v1/collector/noScript.gif?appId=APP_ID">
19
+ </div>
20
+ </noscript>
@@ -0,0 +1,8 @@
1
+ params = {
2
+ :app_id => "APP_ID",
3
+ :cookie_key => "COOKIE_KEY",
4
+ :auth_token => "AUTH_TOKEN"
5
+ }
6
+
7
+
8
+ PxModule.configure(params)
@@ -0,0 +1,62 @@
1
+ Rails.application.routes.draw do
2
+ get 'users/index'
3
+
4
+ get 'home/index'
5
+
6
+ # The priority is based upon order of creation: first created -> highest priority.
7
+ # See how all your routes lay out with "rake routes".
8
+
9
+ # You can have the root of your site routed with "root"
10
+ # root 'welcome#index'
11
+
12
+ root 'home#index'
13
+
14
+ # Example of regular route:
15
+ # get 'products/:id' => 'catalog#view'
16
+
17
+ # Example of named route that can be invoked with purchase_url(id: product.id)
18
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
19
+
20
+ # Example resource route (maps HTTP verbs to controller actions automatically):
21
+ # resources :products
22
+
23
+ # Example resource route with options:
24
+ # resources :products do
25
+ # member do
26
+ # get 'short'
27
+ # post 'toggle'
28
+ # end
29
+ #
30
+ # collection do
31
+ # get 'sold'
32
+ # end
33
+ # end
34
+
35
+ # Example resource route with sub-resources:
36
+ # resources :products do
37
+ # resources :comments, :sales
38
+ # resource :seller
39
+ # end
40
+
41
+ # Example resource route with more complex sub-resources:
42
+ # resources :products do
43
+ # resources :comments
44
+ # resources :sales do
45
+ # get 'recent', on: :collection
46
+ # end
47
+ # end
48
+
49
+ # Example resource route with concerns:
50
+ # concern :toggleable do
51
+ # post 'toggle'
52
+ # end
53
+ # resources :posts, concerns: :toggleable
54
+ # resources :photos, concerns: :toggleable
55
+
56
+ # Example resource route within a namespace:
57
+ # namespace :admin do
58
+ # # Directs /admin/products/* to Admin::ProductsController
59
+ # # (app/controllers/admin/products_controller.rb)
60
+ # resources :products
61
+ # end
62
+ end
@@ -0,0 +1,149 @@
1
+ require 'perimeterx/configuration'
2
+ require 'perimeterx/utils/px_logger'
3
+ require 'perimeterx/utils/px_constants'
4
+ require 'perimeterx/utils/px_http_client'
5
+ require 'perimeterx/utils/px_template_factory'
6
+ require 'perimeterx/internal/perimeter_x_context'
7
+ require 'perimeterx/internal/clients/perimeter_x_activity_client'
8
+ require 'perimeterx/internal/validators/perimeter_x_s2s_validator'
9
+ require 'perimeterx/internal/validators/perimeter_x_cookie_validator'
10
+ require 'perimeterx/internal/validators/perimeter_x_captcha_validator'
11
+
12
+ module PxModule
13
+
14
+ # Module expose API
15
+ def px_verify_request
16
+ verified, px_ctx = PerimeterX.instance.verify(env)
17
+
18
+ # Invalidate _pxCaptcha, can be done only on the controller level
19
+ cookies[:_pxCaptcha] = { value: "", expires: -1.minutes.from_now }
20
+
21
+ if (!verified)
22
+ # In case custon block handler exists
23
+ if (PerimeterX.instance.px_config.key?(:custom_block_handler))
24
+ return PerimeterX.instance.px_config[:custom_block_handler].call(px_ctx)
25
+ elsif (!verified)
26
+ # Generate template
27
+ html = PxTemplateFactory.get_template(px_ctx, PerimeterX.instance.px_config)
28
+ response.headers["Content-Type"] = "text/html"
29
+ response.status = 403
30
+ render :html => html
31
+ end
32
+ end
33
+
34
+ return verified
35
+ end
36
+
37
+ def self.configure(params)
38
+ @px_instance = PerimeterX.configure(params)
39
+ end
40
+
41
+
42
+ # PerimtereX Module
43
+ class PerimeterX
44
+ @@__instance = nil
45
+ @@mutex = Mutex.new
46
+
47
+ attr_reader :px_config
48
+ attr_accessor :px_http_client
49
+ attr_accessor :px_activity_client
50
+
51
+ #Static methods
52
+ def self.configure(params)
53
+ return true if @@__instance
54
+ @@mutex.synchronize {
55
+ return @@__instance if @@__instance
56
+ @@__instance = new(params)
57
+ }
58
+ return true
59
+ end
60
+
61
+ def self.instance
62
+ return @@__instance if !@@__instance.nil?
63
+ raise Exception.new("Please initialize perimeter x first")
64
+ end
65
+
66
+
67
+ #Instance Methods
68
+ def verify(env)
69
+ begin
70
+ @logger.debug("PerimeterX[pxVerify]")
71
+ req = ActionDispatch::Request.new(env)
72
+ if (!@px_config[:module_enabled])
73
+ @logger.warn("Module is disabled")
74
+ return true
75
+ end
76
+ px_ctx = PerimeterXContext.new(@px_config, req)
77
+
78
+ # Captcha phase
79
+ captcha_verified, px_ctx = @px_captcha_validator.verify(px_ctx)
80
+ if (captcha_verified)
81
+ return handle_verification(px_ctx)
82
+ end
83
+
84
+ # Cookie phase
85
+ cookie_verified, px_ctx = @px_cookie_validator.verify(px_ctx)
86
+ if (!cookie_verified)
87
+ @px_s2s_validator.verify(px_ctx)
88
+ end
89
+
90
+ if (@px_config.key?(:custom_verification_handler))
91
+ return @px_config[:custom_verification_handler].call(px_ctx.context)
92
+ else
93
+ return handle_verification(px_ctx)
94
+ end
95
+ rescue Exception => e
96
+ @logger.error("#{e.backtrace.first}: #{e.message} (#{e.class})")
97
+ e.backtrace.drop(1).map { |s| @logger.error("\t#{s}") }
98
+ return true
99
+ end
100
+ end
101
+
102
+ private def initialize(params)
103
+ @px_config = Configuration.new(params).configuration
104
+ @logger = @px_config[:logger]
105
+ @px_http_client = PxHttpClient.new(@px_config)
106
+
107
+ @px_activity_client = PerimeterxActivitiesClient.new(@px_config, @px_http_client)
108
+
109
+ @px_cookie_validator = PerimeterxCookieValidator.new(@px_config)
110
+ @px_s2s_validator = PerimeterxS2SValidator.new(@px_config, @px_http_client)
111
+ @px_captcha_validator = PerimeterxCaptchaValidator.new(@px_config, @px_http_client)
112
+ @logger.debug("PerimeterX[initialize]")
113
+ end
114
+
115
+ private def handle_verification(px_ctx)
116
+ @logger.debug("PerimeterX[handle_verification]")
117
+ @logger.debug("PerimeterX[handle_verification]: processing ended - score:#{px_ctx.context[:score]}, uuid:#{px_ctx.context[:uuid]}")
118
+
119
+ score = px_ctx.context[:score]
120
+ # Case PASS request
121
+ if (score < @px_config[:blocking_score])
122
+ @logger.debug("PerimeterX[handle_verification]: score:#{score} < blocking score, passing request")
123
+ @px_activity_client.send_page_requested_activity(px_ctx)
124
+ return true
125
+ end
126
+
127
+ # Case blocking activity
128
+ @px_activity_client.send_block_activity(px_ctx)
129
+
130
+ # custom_block_handler - custom block handler defined by the user
131
+ if(@px_config.key?(:custom_block_handler))
132
+ @logger.debug("PerimeterX[handle_verification]: custom block handler triggered")
133
+ @px_config[custom_block_handler].call(px_ctx)
134
+ end
135
+
136
+ # In case were in monitor mode, end here
137
+ if(@px_config[:module_mode] == PxModule::MONITOR_MODE)
138
+ @logger.debug("PerimeterX[handle_verification]: monitor mode is on, passing request")
139
+ return true
140
+ end
141
+
142
+ @logger.debug("PerimeterX[handle_verification]: sending block page")
143
+
144
+ return false, px_ctx
145
+ end
146
+
147
+ private_class_method :new
148
+ end
149
+ end
@@ -0,0 +1,37 @@
1
+ require 'perimeterx/utils/px_logger'
2
+ require 'perimeterx/utils/px_constants'
3
+
4
+ module PxModule
5
+ class Configuration
6
+
7
+ attr_accessor :configuration
8
+ attr_accessor :PX_DEFAULT
9
+
10
+ PX_DEFAULT = {
11
+ :app_id => nil,
12
+ :cookie_key => nil,
13
+ :auth_token => nil,
14
+ :module_enabled => true,
15
+ :captcha_enabled => true,
16
+ :challenge_enabled => true,
17
+ :encryption_enabled => true,
18
+ :blocking_score => 70,
19
+ :sensitive_headers => ["http-cookie", "http-cookies"],
20
+ :api_connect_timeout => 0,
21
+ :api_timeout => 0,
22
+ :max_buffer_len => 30,
23
+ :send_page_activities => false,
24
+ :send_block_activities => true,
25
+ :sdk_name => PxModule::SDK_NAME,
26
+ :debug => false,
27
+ :module_mode => PxModule::ACTIVE_MODE,
28
+ :local_proxy => false
29
+ }
30
+
31
+ def initialize(params)
32
+ PX_DEFAULT[:perimeterx_server_host] = "https://sapi-#{params[:app_id].downcase}.perimeterx.net"
33
+ @configuration = PX_DEFAULT.merge(params);
34
+ @configuration[:logger] = PxLogger.new(@configuration[:debug])
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,92 @@
1
+ require 'perimeterx/internal/clients/perimeter_x_risk_client'
2
+
3
+ module PxModule
4
+ class PerimeterxActivitiesClient < PerimeterxRiskClient
5
+
6
+ attr_accessor :activities
7
+
8
+ def initialize(px_config, http_client)
9
+ super(px_config, http_client)
10
+ @logger.debug("PerimeterxActivitiesClients[initialize]")
11
+ @activities = [];
12
+ end
13
+
14
+ def send_to_perimeterx(activity_type, px_ctx, details = [])
15
+ @logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]")
16
+ @logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]: new activity #{activity_type} logged")
17
+
18
+ if (@px_config.key?(:additional_activity_handler))
19
+ @px_config[:additional_activity_handler].call(activity_type, px_ctx, details)
20
+ end
21
+
22
+ details[:module_version] = @px_config[:sdk_name]
23
+ px_data = {
24
+ :type => activity_type,
25
+ :headers => format_headers(px_ctx),
26
+ :timestamp => (Time.now.to_f*1000).floor,
27
+ :socket_ip => px_ctx.context[:ip],
28
+ :px_app_id => @px_config[:app_id],
29
+ :url => px_ctx.context[:full_url],
30
+ :details => details,
31
+ }
32
+
33
+ if (px_ctx.context.key?(:vid))
34
+ @logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]: found vid in ctx")
35
+ px_data[:vid] = px_ctx.context[:vid]
36
+ end
37
+
38
+ # Prepare request
39
+ headers = {
40
+ "Authorization" => "Bearer #{@px_config[:auth_token]}" ,
41
+ "Content-Type" => "application/json"
42
+ };
43
+
44
+ @activities.push(px_data)
45
+ if (@activities.size == @px_config[:max_buffer_len])
46
+ @logger.debug("PerimeterxActivitiesClients[send_to_perimeterx]: max buffer length reached, sending activities")
47
+ @http_client.async_post(PxModule::API_V1_S2S, @activities, headers)
48
+
49
+ @activities.clear
50
+ end
51
+ end
52
+
53
+ def send_block_activity(px_ctx)
54
+ @logger.debug("PerimeterxActivitiesClients[send_block_activity]")
55
+ if (!@px_config[:send_page_acitivites])
56
+ @logger.debug("PerimeterxActivitiesClients[send_block_activity]: sending activites is disabled")
57
+ return
58
+ end
59
+
60
+ details = {
61
+ :block_uuid => px_ctx.context[:uuid],
62
+ :block_score => px_ctx.context[:score],
63
+ :block_reason => px_ctx.context[:block_reason]
64
+ }
65
+
66
+ send_to_perimeterx(PxModule::BLOCK_ACTIVITY, px_ctx, details)
67
+
68
+ end
69
+
70
+ def send_page_requested_activity(px_ctx)
71
+ @logger.debug("PerimeterxActivitiesClients[send_page_requested_activity]")
72
+ if (!@px_config[:send_page_acitivites])
73
+ return
74
+ end
75
+
76
+ details = {
77
+ :http_version => px_ctx.context[:http_version],
78
+ :http_method => px_ctx.context[:http_method]
79
+ }
80
+
81
+ if (px_ctx.context.key?(:decoded_cookie))
82
+ details[:px_cookie] = px_ctx.context[:decoded_cookie]
83
+ end
84
+
85
+ if (px_ctx.context.key?(:cookie_hmac))
86
+ details[:px_cookie_hmac] = px_ctx.context[:cookie_hmac]
87
+ end
88
+
89
+ send_to_perimeterx(PxModule::PAGE_REQUESTED_ACTIVITY, px_ctx, details)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,28 @@
1
+ require 'perimeterx/utils/px_logger'
2
+
3
+ module PxModule
4
+ class PerimeterxRiskClient
5
+ attr_accessor :px_config
6
+ attr_accessor :http_client
7
+
8
+ def initialize(px_config, http_client)
9
+ @px_config = px_config
10
+ @http_client = http_client;
11
+ @logger = px_config[:logger]
12
+ end
13
+
14
+ def format_headers(px_ctx)
15
+ @logger.debug("PerimeterxRiskClient[format_headers]")
16
+ formated_headers = []
17
+ px_ctx.context[:headers].each do |k,v|
18
+ if (!@px_config[:sensitive_headers].include? k.to_s)
19
+ formated_headers.push({
20
+ :name => k.to_s,
21
+ :value => v
22
+ })
23
+ end #end if
24
+ end #end forech
25
+ return formated_headers
26
+ end #end method
27
+ end #end class
28
+ end
@@ -0,0 +1,5 @@
1
+ class PxCookieDecryptionException < StandardError
2
+ def initialize(msg)
3
+ super(msg)
4
+ end
5
+ end