Commit 952bd59d authored by Mike Greiling's avatar Mike Greiling Committed by Mike Greiling

Merge branch 'import-symlinks-8-17' into 'security-8-17'

Fix file disclosure via hidden symlinks using the project import (8.17)

See merge request !2160
parent c0ab38a3
---
title: Remove hidden symlinks from project import files
merge_request:
author:
......@@ -47,12 +47,16 @@ module Gitlab
end
def remove_symlinks!
Dir["#{@shared.export_path}/**/*"].each do |path|
extracted_files.each do |path|
FileUtils.rm(path) if File.lstat(path).symlink?
end
true
end
def extracted_files
Dir.glob("#{@shared.export_path}/**/*", File::FNM_DOTMATCH).reject { |f| f =~ /.*\/\.{1,2}$/ }
end
end
end
end
......@@ -5,6 +5,7 @@ describe Gitlab::ImportExport::FileImporter, lib: true do
let(:export_path) { "#{Dir::tmpdir}/file_importer_spec" }
let(:valid_file) { "#{shared.export_path}/valid.json" }
let(:symlink_file) { "#{shared.export_path}/invalid.json" }
let(:hidden_symlink_file) { "#{shared.export_path}/.hidden" }
let(:subfolder_symlink_file) { "#{shared.export_path}/subfolder/invalid.json" }
before do
......@@ -25,6 +26,10 @@ describe Gitlab::ImportExport::FileImporter, lib: true do
expect(File.exist?(symlink_file)).to be false
end
it 'removes hidden symlinks in root folder' do
expect(File.exist?(hidden_symlink_file)).to be false
end
it 'removes symlinks in subfolders' do
expect(File.exist?(subfolder_symlink_file)).to be false
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