diff options
Diffstat (limited to 'app/models/application_setting_implementation.rb')
-rw-r--r-- | app/models/application_setting_implementation.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/app/models/application_setting_implementation.rb b/app/models/application_setting_implementation.rb index d1a919fc01a..5ad382d8670 100644 --- a/app/models/application_setting_implementation.rb +++ b/app/models/application_setting_implementation.rb @@ -361,18 +361,33 @@ module ApplicationSettingImplementation def separate_whitelists(string_array) string_array.reduce([[], []]) do |(ip_whitelist, domain_whitelist), string| - ip_obj = Gitlab::Utils.string_to_ip_object(string) + address, port = parse_addr_and_port(string) + + ip_obj = Gitlab::Utils.string_to_ip_object(address) if ip_obj - ip_whitelist << ip_obj + ip_whitelist << Gitlab::UrlBlockers::IpWhitelistEntry.new(ip_obj, port: port) else - domain_whitelist << string + domain_whitelist << Gitlab::UrlBlockers::DomainWhitelistEntry.new(address, port: port) end [ip_whitelist, domain_whitelist] end end + def parse_addr_and_port(str) + case str + when /\A\[(?<address> .* )\]:(?<port> \d+ )\z/x # string like "[::1]:80" + address, port = $~[:address], $~[:port] + when /\A(?<address> [^:]+ ):(?<port> \d+ )\z/x # string like "127.0.0.1:80" + address, port = $~[:address], $~[:port] + else # string with no port number + address, port = str, nil + end + + [address, port&.to_i] + end + def array_to_string(arr) arr&.join("\n") end |