summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-07-26 13:40:57 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-07-26 13:40:57 +0000
commitf65ed87489e81ade3d3d78098db75a60db8eb893 (patch)
tree8a9fa12ebf81b134920a759866db7fd49cb65b59 /lib
parent461101c3b50ef2215a3be9a099bf2581473d7d2d (diff)
parentf5c1cd489834e824c83f2ae909cd0dd41fb95dab (diff)
downloadgitlab-ce-f65ed87489e81ade3d3d78098db75a60db8eb893.tar.gz
Merge branch 'security-dns-ssrf-bypass' into 'master'
Server Side Request Forgery mitigation bypass Closes #2872 See merge request gitlab/gitlabhq!3205
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/url_blocker.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/gitlab/url_blocker.rb b/lib/gitlab/url_blocker.rb
index f6b2e2acf16..cc937cbb3cf 100644
--- a/lib/gitlab/url_blocker.rb
+++ b/lib/gitlab/url_blocker.rb
@@ -85,9 +85,9 @@ module Gitlab
# we'll be making the request to the IP address, instead of using the hostname.
def enforce_uri_hostname(addrs_info, uri, hostname, dns_rebind_protection)
address = addrs_info.first
- ip_address = address&.ip_address
+ ip_address = address.ip_address
- return [uri, nil] unless dns_rebind_protection && ip_address && ip_address != hostname
+ return [uri, nil] unless dns_rebind_protection && ip_address != hostname
uri = uri.dup
uri.hostname = ip_address
@@ -111,6 +111,15 @@ module Gitlab
addr.ipv6_v4mapped? ? addr.ipv6_to_ipv4 : addr
end
rescue SocketError
+ # In the test suite we use a lot of mocked urls that are either invalid or
+ # don't exist. In order to avoid modifying a ton of tests and factories
+ # we allow invalid urls unless the environment variable RSPEC_ALLOW_INVALID_URLS
+ # is not true
+ return if Rails.env.test? && ENV['RSPEC_ALLOW_INVALID_URLS'] == 'true'
+
+ # If the addr can't be resolved or the url is invalid (i.e http://1.1.1.1.1)
+ # we block the url
+ raise BlockedUrlError, "Host cannot be resolved or invalid"
end
def validate_local_request(address_info:, allow_localhost:, allow_local_network:)