Skip to content
Snippets Groups Projects
Commit 72af766a authored by John Jarvis's avatar John Jarvis
Browse files

Merge branch 'security-2754-fix-lfs-import-11-3' into 'security-11-3'

[11.3] Validate LFS hrefs before downloading them

See merge request gitlab/gitlabhq!2700
parent 60c89f44
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -4,12 +4,15 @@
module Projects
module LfsPointers
class LfsDownloadService < BaseService
VALID_PROTOCOLS = %w[http https].freeze
def execute(oid, url)
return unless project&.lfs_enabled? && oid.present? && url.present?
 
return if LfsObject.exists?(oid: oid)
 
sanitized_uri = Gitlab::UrlSanitizer.new(url)
Gitlab::UrlBlocker.validate!(sanitized_uri.sanitized_url, protocols: VALID_PROTOCOLS)
 
with_tmp_file(oid) do |file|
size = download_and_save_file(file, sanitized_uri)
Loading
Loading
---
title: Validate LFS hrefs before downloading them
merge_request:
author:
type: security
Loading
Loading
@@ -54,6 +54,18 @@ describe Projects::LfsPointers::LfsDownloadService do
end
end
 
context 'when a bad URL is used' do
where(download_link: ['/etc/passwd', 'ftp://example.com', 'http://127.0.0.2'])
with_them do
it 'does not download the file' do
expect(subject).not_to receive(:download_and_save_file)
expect { subject.execute(oid, download_link) }.not_to change { LfsObject.count }
end
end
end
context 'when an lfs object with the same oid already exists' do
before do
create(:lfs_object, oid: 'oid')
Loading
Loading
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