diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2019-01-16 17:29:21 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-01-16 17:29:21 +0000 |
commit | cdaef30e47909b438837a4c7bb31b1fab3eb34d7 (patch) | |
tree | 75f468d7cd2396b8e67036347716a29ab1f646c1 /lib | |
parent | 6617a575ee961370d4dbfa672eff64be9f9e4315 (diff) | |
parent | 067dc6540ca625b61648a73ebba05191b2c632dd (diff) | |
download | gitlab-ce-cdaef30e47909b438837a4c7bb31b1fab3eb34d7.tar.gz |
Merge branch 'security-2770-verify-bundle-import-files' into 'master'
[master] Validate bundle files before unpacking them
Closes #2770
See merge request gitlab/gitlabhq!2772
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/bundle_file.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 5 |
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/git/bundle_file.rb b/lib/gitlab/git/bundle_file.rb new file mode 100644 index 00000000000..8384a436fcc --- /dev/null +++ b/lib/gitlab/git/bundle_file.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Gitlab + module Git + class BundleFile + # All git bundle files start with this string + # + # https://github.com/git/git/blob/v2.20.1/bundle.c#L15 + MAGIC = "# v2 git bundle\n" + + InvalidBundleError = Class.new(StandardError) + + attr_reader :filename + + def self.check!(filename) + new(filename).check! + end + + def initialize(filename) + @filename = filename + end + + def check! + data = File.open(filename, 'r') { |f| f.read(MAGIC.size) } + + raise InvalidBundleError, 'Invalid bundle file' unless data == MAGIC + end + end + end +end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 5bbedc9d5e3..786c90f9272 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -789,6 +789,11 @@ module Gitlab end def create_from_bundle(bundle_path) + # It's important to check that the linked-to file is actually a valid + # .bundle file as it is passed to `git clone`, which may otherwise + # interpret it as a pointer to another repository + ::Gitlab::Git::BundleFile.check!(bundle_path) + gitaly_repository_client.create_from_bundle(bundle_path) end |