diff options
author | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-07-24 17:46:57 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-07-24 17:46:57 +0000 |
commit | e5269690c90cd4240f0abda3e6ae801fea963307 (patch) | |
tree | 3aef912723c0efb3b470b42c44c6f023c6956fef /spec | |
parent | 4065e0b288b01f1d0b6fd912126908a17370f17b (diff) | |
parent | 50e3b0291659e998b0ce0bb17b19a4061cf4f3cd (diff) | |
download | gitlab-ce-e5269690c90cd4240f0abda3e6ae801fea963307.tar.gz |
Merge branch 'security-github-ssrf-redirect-12-0' into '12-0-stable'
Do not allow localhost url redirection in GitHub Integration
See merge request gitlab/gitlabhq!3206
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/octokit/middleware_spec.rb | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/lib/gitlab/octokit/middleware_spec.rb b/spec/lib/gitlab/octokit/middleware_spec.rb new file mode 100644 index 00000000000..7f2b523f5b7 --- /dev/null +++ b/spec/lib/gitlab/octokit/middleware_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe Gitlab::Octokit::Middleware do + let(:app) { double(:app) } + let(:middleware) { described_class.new(app) } + + shared_examples 'Public URL' do + it 'does not raise an error' do + expect(app).to receive(:call).with(env) + + expect { middleware.call(env) }.not_to raise_error + end + end + + shared_examples 'Local URL' do + it 'raises an error' do + expect { middleware.call(env) }.to raise_error(Gitlab::UrlBlocker::BlockedUrlError) + end + end + + describe '#call' do + context 'when the URL is a public URL' do + let(:env) { { url: 'https://public-url.com' } } + + it_behaves_like 'Public URL' + end + + context 'when the URL is a localhost adresss' do + let(:env) { { url: 'http://127.0.0.1' } } + + context 'when localhost requests are not allowed' do + before do + stub_application_setting(allow_local_requests_from_hooks_and_services: false) + end + + it_behaves_like 'Local URL' + end + + context 'when localhost requests are allowed' do + before do + stub_application_setting(allow_local_requests_from_hooks_and_services: true) + end + + it_behaves_like 'Public URL' + end + end + + context 'when the URL is a local network address' do + let(:env) { { url: 'http://172.16.0.0' } } + + context 'when local network requests are not allowed' do + before do + stub_application_setting(allow_local_requests_from_hooks_and_services: false) + end + + it_behaves_like 'Local URL' + end + + context 'when local network requests are allowed' do + before do + stub_application_setting(allow_local_requests_from_hooks_and_services: true) + end + + it_behaves_like 'Public URL' + end + end + end +end |