2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'doorkeeper/grape/authorization_decorator'
|
|
|
|
|
|
|
|
class Rack::Attack
|
|
|
|
class Request
|
|
|
|
def remote_ip
|
2019-07-04 09:05:34 +01:00
|
|
|
# @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
|
|
|
|
# @env['HTTP_CF_CONNECTING_IP'] ? @env['HTTP_CF_CONNECTING_IP'] : ip
|
|
|
|
@remote_ip ||= (@env["HTTP_CF_CONNECTING_IP"] || ip).to_s
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Always allow requests from localhost
|
|
|
|
# (blocklist & throttles are skipped)
|
|
|
|
Rack::Attack.safelist('allow from localhost') do |req|
|
|
|
|
# Requests are allowed if the return value is truthy
|
|
|
|
req.remote_ip == '127.0.0.1' || req.remote_ip == '::1'
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|