Class: PxModule::PerimeterXContext
- Inherits:
-
Object
- Object
- PxModule::PerimeterXContext
- Defined in:
- lib/perimeterx/internal/perimeter_x_context.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#px_config ⇒ Object
Returns the value of attribute px_config.
Instance Method Summary collapse
-
#check_sensitive_route(sensitive_routes, uri) ⇒ Object
end init.
- #get_px_cookie ⇒ Object
-
#initialize(px_config, req) ⇒ PerimeterXContext
constructor
A new instance of PerimeterXContext.
- #set_block_action_type(action) ⇒ Object
Constructor Details
#initialize(px_config, req) ⇒ PerimeterXContext
Returns a new instance of PerimeterXContext.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/perimeterx/internal/perimeter_x_context.rb', line 9 def initialize(px_config, req) @logger = px_config[:logger] @logger.debug('PerimeterXContext[initialize]') @context = Hash.new @context[:px_cookie] = Hash.new @context[:headers] = Hash.new @context[:cookie_origin] = 'cookie' = req. # Get token from header if req.headers[PxModule::TOKEN_HEADER] @context[:cookie_origin] = 'header' token = req.headers[PxModule::TOKEN_HEADER] if token.include? ':' exploded_token = token.split(':', 2) = "v#{exploded_token[0]}".to_sym @context[:px_cookie][] = exploded_token[1] end elsif !.empty? # Get cookie from jar # Prepare hashed cookies .each do |k, v| case k.to_s when '_px3' @context[:px_cookie][:v3] = v when '_px' @context[:px_cookie][:v1] = v when '_pxCaptcha' @context[:px_captcha] = v end end #end case end #end empty cookies req.headers.each do |k, v| if (k.start_with? 'HTTP_') header = k.to_s.gsub('HTTP_', '') header = header.gsub('_', '-').downcase @context[:headers][header.to_sym] = v end end #end headers foreach @context[:hostname]= req.server_name @context[:user_agent] = req.user_agent ? req.user_agent : '' @context[:uri] = px_config[:custom_uri] ? px_config[:custom_uri].call(req) : req.fullpath @context[:full_url] = req.original_url @context[:format] = req.format.symbol @context[:score] = 0 if px_config.key?(:custom_user_ip) @context[:ip] = req.headers[px_config[:custom_user_ip]] elsif px_config.key?(:px_custom_user_ip_method) @context[:ip] = px_config[:px_custom_user_ip_method].call(req) else @context[:ip] = req.ip end if req.server_protocol httpVer = req.server_protocol.split('/') if httpVer.size > 0 @context[:http_version] = httpVer[1] end end @context[:http_method] = req.method @context[:sensitive_route] = check_sensitive_route(px_config[:sensitive_routes], @context[:uri]) end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
6 7 8 |
# File 'lib/perimeterx/internal/perimeter_x_context.rb', line 6 def context @context end |
#px_config ⇒ Object
Returns the value of attribute px_config.
7 8 9 |
# File 'lib/perimeterx/internal/perimeter_x_context.rb', line 7 def px_config @px_config end |
Instance Method Details
#check_sensitive_route(sensitive_routes, uri) ⇒ Object
end init
75 76 77 78 79 80 |
# File 'lib/perimeterx/internal/perimeter_x_context.rb', line 75 def check_sensitive_route(sensitive_routes, uri) sensitive_routes.each do |sensitive_route| return true if uri.start_with? sensitive_route end false end |
#get_px_cookie ⇒ Object
95 96 97 98 |
# File 'lib/perimeterx/internal/perimeter_x_context.rb', line 95 def = @context[:px_cookie].key?(:v3) ? @context[:px_cookie][:v3] : @context[:px_cookie][:v1] return .tr(' ','+') if !.nil? end |
#set_block_action_type(action) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/perimeterx/internal/perimeter_x_context.rb', line 82 def set_block_action_type(action) @context[:block_action] = case action when 'c' 'captcha' when 'b' return 'block' when 'j' return 'challenge' else return captcha end end |