Skip to content
Snippets Groups Projects
Commit 213f4149 authored by Luke Duncalfe's avatar Luke Duncalfe :two:
Browse files

Revert use in DAST

parent 9a8a8c3d
No related branches found
No related tags found
2 merge requests!170053Security patch upgrade alert: Only expose to admins 17-4,!167690Capture scheme and port in source user hostname
......@@ -164,6 +164,7 @@ Style/FormatString:
- 'ee/app/models/dast/profile.rb'
- 'ee/app/models/dast/site_profile_secret_variable.rb'
- 'ee/app/models/dast_site_profile.rb'
- 'ee/app/models/dast_site_validation.rb'
- 'ee/app/models/geo/upload_registry.rb'
- 'ee/app/models/integrations/github.rb'
- 'ee/app/models/iterations/cadence.rb'
......
......@@ -71,7 +71,9 @@ def validation_url
end
def self.get_normalized_url_base(url)
::Gitlab::UrlHelpers.normalized_base_url(url, always_port: true)
uri = Addressable::URI.parse(url)
"%{scheme}://%{host}:%{port}" % { scheme: uri.scheme, host: uri.host, port: uri.inferred_port }
end
private
......
......@@ -16,14 +16,13 @@ def self.as_wss(url)
# Returns hostname of a URL.
#
# @param url [String] URL to parse
# @param always_port [Boolean] when `true`, a port will always be added (default `false`).
# @return [String|Nilclass] Normalized base URL, or nil if url was unparsable.
def self.normalized_base_url(url, always_port: false)
def self.normalized_base_url(url)
parsed = Utils.parse_url(url)
return unless parsed
if parsed.port || always_port
format("%{scheme}://%{host}:%{port}", scheme: parsed.scheme, host: parsed.host, port: parsed.inferred_port)
if parsed.port
format("%{scheme}://%{host}:%{port}", scheme: parsed.scheme, host: parsed.host, port: parsed.port)
else
format("%{scheme}://%{host}", scheme: parsed.scheme, host: parsed.host)
end
......
......@@ -17,17 +17,5 @@
with_them do
it { expect(described_class.normalized_base_url(url)).to eq(value) }
end
context 'when `always_port` is true' do
where(:url, :value) do
'ssh://foo:bar@example.com' | 'ssh://example.com:22'
'http://foo:bar@example.com:3000/dir' | 'http://example.com:3000'
'http://foo:bar@example.com/dir' | 'http://example.com:80'
end
with_them do
it { expect(described_class.normalized_base_url(url, always_port: true)).to eq(value) }
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment