Commit 23a1168b authored by George Koltsov's avatar George Koltsov

Fix 500 on Gitea importer

- When entering blocked URLs Gitea importer
  returns 500 error instead of a user friendly error
- Thic change fixes 500 error and adds more user
  friendly error indicating what went wrong
parent b119a04f
...@@ -16,8 +16,14 @@ class Import::GiteaController < Import::GithubController ...@@ -16,8 +16,14 @@ class Import::GiteaController < Import::GithubController
# Must be defined or it will 404 # Must be defined or it will 404
def status def status
if blocked_url?
session[access_token_key] = nil
redirect_to new_import_url, alert: _('Specified URL cannot be used.')
else
super super
end end
end
private private
...@@ -54,4 +60,19 @@ class Import::GiteaController < Import::GithubController ...@@ -54,4 +60,19 @@ class Import::GiteaController < Import::GithubController
def client_options def client_options
{ host: provider_url, api_version: 'v1' } { host: provider_url, api_version: 'v1' }
end end
def blocked_url?
Gitlab::UrlBlocker.blocked_url?(
provider_url,
{
allow_localhost: allow_local_requests?,
allow_local_network: allow_local_requests?,
schemes: %w(http https)
}
)
end
def allow_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end
end end
---
title: Fix 500 Error when using Gitea Importer
merge_request: 26166
author:
type: fixed
...@@ -18466,6 +18466,9 @@ msgstr "" ...@@ -18466,6 +18466,9 @@ msgstr ""
msgid "Specific Runners" msgid "Specific Runners"
msgstr "" msgstr ""
msgid "Specified URL cannot be used."
msgstr ""
msgid "Specify an e-mail address regex pattern to identify default internal users." msgid "Specify an e-mail address regex pattern to identify default internal users."
msgstr "" msgstr ""
......
...@@ -28,10 +28,24 @@ describe Import::GiteaController do ...@@ -28,10 +28,24 @@ describe Import::GiteaController do
describe "GET status" do describe "GET status" do
it_behaves_like 'a GitHub-ish import controller: GET status' do it_behaves_like 'a GitHub-ish import controller: GET status' do
let(:extra_assign_expectations) { { gitea_host_url: host_url } }
before do before do
assign_host_url assign_host_url
end end
let(:extra_assign_expectations) { { gitea_host_url: host_url } }
context 'when host url is local or not http' do
%w[https://localhost:3000 http://192.168.0.1 ftp://testing].each do |url|
let(:host_url) { url }
it 'denies network request' do
get :status, format: :json
expect(controller).to redirect_to(new_import_url)
expect(flash[:alert]).to eq('Specified URL cannot be used.')
end
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment