8000 Fix CVE-2018-1000544 symlink path traversal · rubyzip/rubyzip@d68fbd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d68fbd2

Browse files
committed
Fix CVE-2018-1000544 symlink path traversal
Not sure if the exception is the right way to go
1 parent f6e76d6 commit d68fbd2

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lib/zip/entry.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def extract(dest_path = nil, &block)
154154
elsif @name.squeeze('/') =~ /\.{2}(?:\/|\z)/
155155
puts "WARNING: skipped \"../\" path component(s) in #{@name}"
156156
return self
157+
elsif symlink? && get_input_stream.read =~ %r{../..}
158+
puts "WARNING: skipped \"#{get_input_stream.read}\" symlink path in #{@name}"
159+
return self
157160
end
158161

159162
dest_path ||= @name

test/data/symlink.zip

330 Bytes
Binary file not shown.

test/entry_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,14 @@ def test_entry_name_with_absolute_path_extract_when_given_different_path
177177

178178
assert File.exist?("#{path}/tmp/file.txt")
179179
end
180+
181+
def test_entry_name_with_relative_symlink
182+
assert_raises Errno::ENOENT do
183+
Zip::File.open('test/data/symlink.zip') do |zip_file|
184+
zip_file.each do |entry|
185+
entry.extract
186+
end
187+
end
188+
end
189+
end
180190
end

0 commit comments

Comments
 (0)
0