Method: PxModule::PerimeterX#verify

Defined in:
lib/perimeter_x.rb

#verify(env) ⇒ Object

Instance Methods



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/perimeter_x.rb', line 70

def verify(env)
  begin
    @logger.debug("PerimeterX[pxVerify]")
    req = ActionDispatch::Request.new(env)
    if (!@px_config[:module_enabled])
      @logger.warn("Module is disabled")
      return true
    end
    px_ctx = PerimeterXContext.new(@px_config, req)

    # Captcha phase
    captcha_verified, px_ctx = @px_captcha_validator.verify(px_ctx)
    if (captcha_verified)
      return handle_verification(px_ctx)
    end

    # Cookie phase
    cookie_verified, px_ctx = @px_cookie_validator.verify(px_ctx)
    if (!cookie_verified)
      @px_s2s_validator.verify(px_ctx)
    end

    if (@px_config.key?(:custom_verification_handler))
      return @px_config[:custom_verification_handler].call(px_ctx.context)
    else
      return handle_verification(px_ctx)
    end
  rescue Exception => e
    @logger.error("#{e.backtrace.first}: #{e.message} (#{e.class})")
    e.backtrace.drop(1).map { |s| @logger.error("\t#{s}") }
    return true
  end
end