retrospring/lib/constraints/local_network.rb
Georg Gadinger 64adbb5707 allow /metrics to be reached from private subnets only
this commit is not approved by the IPv6 crowd.  patches welcome
2023-02-13 22:17:46 +01:00

22 lines
372 B
Ruby

# frozen_string_literal: true
module Constraints
module LocalNetwork
module_function
SUBNETS = %w[
10.0.0.0/8
127.0.0.0/8
172.16.0.0/12
192.168.0.0/16
].map { IPAddr.new(_1) }.freeze
def matches?(request)
SUBNETS.find do |net|
net.include? request.remote_ip
rescue
false
end
end
end
end