2019-09-13 09:26:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module UrlBlockers
|
2020-10-29 02:08:45 -04:00
|
|
|
class UrlAllowlist
|
2019-09-13 09:26:31 -04:00
|
|
|
class << self
|
2020-10-29 02:08:45 -04:00
|
|
|
def ip_allowed?(ip_string, port: nil)
|
2019-09-13 09:26:31 -04:00
|
|
|
return false if ip_string.blank?
|
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
ip_allowlist, _ = outbound_local_requests_allowlist_arrays
|
2019-09-13 09:26:31 -04:00
|
|
|
ip_obj = Gitlab::Utils.string_to_ip_object(ip_string)
|
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
ip_allowlist.any? do |ip_allowlist_entry|
|
|
|
|
ip_allowlist_entry.match?(ip_obj, port)
|
2020-03-15 23:09:14 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
end
|
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
def domain_allowed?(domain_string, port: nil)
|
2019-09-13 09:26:31 -04:00
|
|
|
return false if domain_string.blank?
|
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
_, domain_allowlist = outbound_local_requests_allowlist_arrays
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
domain_allowlist.any? do |domain_allowlist_entry|
|
|
|
|
domain_allowlist_entry.match?(domain_string, port)
|
2020-03-15 23:09:14 -04:00
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# We cannot use Gitlab::CurrentSettings as ApplicationSetting itself
|
|
|
|
# calls this class. This ends up in a cycle where
|
|
|
|
# Gitlab::CurrentSettings creates an ApplicationSetting which then
|
|
|
|
# calls this method.
|
|
|
|
#
|
2019-09-18 10:02:45 -04:00
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/issues/9833
|
2020-10-29 02:08:45 -04:00
|
|
|
def outbound_local_requests_allowlist_arrays
|
2019-09-13 09:26:31 -04:00
|
|
|
return [[], []] unless ApplicationSetting.current
|
|
|
|
|
2020-10-29 02:08:45 -04:00
|
|
|
ApplicationSetting.current.outbound_local_requests_allowlist_arrays
|
2019-09-13 09:26:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|