Skip to content

Commit

Permalink
Fix CVE-2018-1000544 symlink path traversal
Browse files Browse the repository at this point in the history
Not sure if the exception is the right way to go
  • Loading branch information
bdewater committed Jul 1, 2018
1 parent f6e76d6 commit 472acab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/zip/entry.rb
Expand Up @@ -154,6 +154,9 @@ def extract(dest_path = nil, &block)
elsif @name.squeeze('/') =~ /\.{2}(?:\/|\z)/
puts "WARNING: skipped \"../\" path component(s) in #{@name}"
return self
elsif ftype == :symlink && get_input_stream.read =~ %r{../..}
puts "WARNING: skipped \"#{get_input_stream.read}\" symlink path in #{@name}"
return self
end

dest_path ||= @name
Expand Down
Binary file added test/data/symlink.zip
Binary file not shown.
10 changes: 10 additions & 0 deletions test/entry_test.rb
Expand Up @@ -177,4 +177,14 @@ def test_entry_name_with_absolute_path_extract_when_given_different_path

assert File.exist?("#{path}/tmp/file.txt")
end

def test_entry_name_with_relative_symlink
assert_raises Errno::ENOENT do
Zip::File.open('test/data/symlink.zip') do |zip_file|
zip_file.each do |entry|
entry.extract
end
end
end
end
end

0 comments on commit 472acab

Please sign in to comment.