Sha256: 8c4eacbc14c136459fc6286a7c13493abdeabd170816a6f32d07d46182164f2c

Contents?: true

Size: 1.31 KB

Versions: 105

Compression:

Stored size: 1.31 KB

Contents

module ForestLiana
  class BaseController < ::ActionController::Base
    skip_before_action :verify_authenticity_token, raise: false
    wrap_parameters false
    before_action :reject_unauthorized_ip

    def route_not_found
      head :not_found
    end

    private

    def reject_unauthorized_ip
      begin
        ip = request.remote_ip

        if !ForestLiana::IpWhitelist.is_ip_whitelist_retrieved || !ForestLiana::IpWhitelist.is_ip_valid(ip)
          unless ForestLiana::IpWhitelist.retrieve
            raise ForestLiana::Errors::HTTP403Error.new("IP whitelist not retrieved")
          end

          unless ForestLiana::IpWhitelist.is_ip_valid(ip)
            raise ForestLiana::Errors::HTTP403Error.new("IP address rejected (#{ip})")
          end
        end
      rescue ForestLiana::Errors::ExpectedError => exception
        error_data = ForestAdmin::JSONAPI::Serializer.serialize_errors([{
          status: exception.error_code,
          detail: exception.message
        }])
        render(serializer: nil, json: error_data, status: exception.status)
      rescue => exception
        FOREST_REPORTER.report exception
        FOREST_LOGGER.error(exception)
        FOREST_LOGGER.error(exception.backtrace.join("\n"))
        render(serializer: nil, json: nil, status: :internal_server_error)
      end
    end
  end
end

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
forest_liana-9.7.0 app/controllers/forest_liana/base_controller.rb
forest_liana-9.6.4 app/controllers/forest_liana/base_controller.rb
forest_liana-9.6.3 app/controllers/forest_liana/base_controller.rb
forest_liana-9.6.0 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.7 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.6 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.5 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.4 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.3 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.2 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.1 app/controllers/forest_liana/base_controller.rb
forest_liana-9.5.0 app/controllers/forest_liana/base_controller.rb
forest_liana-9.4.3 app/controllers/forest_liana/base_controller.rb
forest_liana-9.4.2 app/controllers/forest_liana/base_controller.rb
forest_liana-9.4.1 app/controllers/forest_liana/base_controller.rb
forest_liana-9.4.0 app/controllers/forest_liana/base_controller.rb
forest_liana-8.3.3 app/controllers/forest_liana/base_controller.rb
forest_liana-9.3.16 app/controllers/forest_liana/base_controller.rb
forest_liana-9.3.15 app/controllers/forest_liana/base_controller.rb
forest_liana-9.3.14 app/controllers/forest_liana/base_controller.rb