Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CVE-2018-1000544 #371

Merged
merged 4 commits into from Aug 31, 2018
Merged

Fix CVE-2018-1000544 #371

merged 4 commits into from Aug 31, 2018

Conversation

@bdewater
Copy link
Contributor

@bdewater bdewater commented Jul 1, 2018

Attempt to fix #369

Not sure if there's a better way to handle Errno::ENOENT in the symlink case, open to suggstions.

@bdewater bdewater force-pushed the bdewater:fix-cve-2018-1000544 branch from 7720b14 to 2425c91 Jul 1, 2018
@coveralls
Copy link

@coveralls coveralls commented Jul 1, 2018

Coverage Status

Coverage decreased (-2.3%) to 94.268% when pulling 7720b14 on bdewater:fix-cve-2018-1000544 into 8887b70 on rubyzip:master.

@coveralls
Copy link

@coveralls coveralls commented Jul 1, 2018

Coverage Status

Coverage decreased (-4.08%) to 94.718% when pulling 0586329 on bdewater:fix-cve-2018-1000544 into e89f6ac on rubyzip:master.

@bdewater bdewater force-pushed the bdewater:fix-cve-2018-1000544 branch from 2425c91 to 472acab Jul 1, 2018
@bdewater
Copy link
Contributor Author

@bdewater bdewater commented Jul 1, 2018

CI failures are unrelated (JRuby installation 404s)

@bdewater bdewater force-pushed the bdewater:fix-cve-2018-1000544 branch from 472acab to d68fbd2 Jul 1, 2018
@JackMc
JackMc approved these changes Jul 2, 2018
Copy link

@JackMc JackMc left a comment

A few comments, but this looks good to me

if @name.squeeze('/') =~ /\.{2}(?:\/|\z)/
def extract(dest_path = nil, &block)
if dest_path.nil? && Pathname.new(@name).absolute?
puts "WARNING: skipped absolute path in #{@name}"

This comment has been minimized.

@JackMc

JackMc Jul 2, 2018

Is putsing a warning the best thing (most extensible) way to do things? I recognize that's what the previous code did, but it seems off to me. Maybe we should raise, or is there some kind of error reporting mechanism that we can surface to the user that's zipfile-wide?

This comment has been minimized.

@JackMc

JackMc Jul 2, 2018

Either way feel free to say that this is out of scope :)

puts "WARNING: skipped \"../\" path component(s) in #{@name}"
return self
elsif symlink? && get_input_stream.read =~ %r{../..}

This comment has been minimized.

@JackMc

JackMc Jul 2, 2018

Could you add a test that this still works for non-malicious symlinks? It doesn't appear there is one.

The comment on get_input_stream's definition seems to also say that it doesn't work too great for symlinks. We should make sure we're not adding any undefined behaviour: https://github.com/rubyzip/rubyzip/blob/master/lib/zip/entry.rb#L484

This comment has been minimized.

@tuzovakaoff

tuzovakaoff Jul 2, 2018

Symlink could also links to absolute path
You can find examples of such zip files in https://github.com/jwilk/path-traversal-samples

@zeha
Copy link

@zeha zeha commented Aug 12, 2018

Given this doesn't look too broken, can we please have that merged and a new release stamped with it? Thanks :-)

if dest_path.nil? && Pathname.new(@name).absolute?
puts "WARNING: skipped absolute path in #{@name}"
return self
elsif @name.squeeze('/') =~ /\.{2}(?:\/|\z)/

This comment has been minimized.

@zeha

zeha Aug 15, 2018

Should this not also gain the dest_path.nil? check?

@zeha
Copy link

@zeha zeha commented Aug 15, 2018

Example in README calls .extract() with the name from the zipfile, leading to the same vulnerability in code that gets copy-pasted from the README.

@drn
Copy link

@drn drn commented Aug 21, 2018

Our team would love to see this merged and released as well. This has started to show up in our automated vulnerability analysis (https://hakiri.io/technologies/rubyzip/issues/1e6c19ff65e713) and our builds are red as a result.

Happy to help get this over the line if any additional work is needed. Please let me know!

@bdewater
Copy link
Contributor Author

@bdewater bdewater commented Aug 21, 2018

I can address feedback to this PR - @simonoff have you had a chance to look at this?

Right now do not have the bandwidth available to look at/add tests for all the examples in https://github.com/jwilk/path-traversal-samples - so if somebody feels like taking a crack at it you're most welcome 🙂

@simonoff
Copy link
Member

@simonoff simonoff commented Aug 22, 2018

Tests is failed. Need to have a green build to make it merged.

@bdewater
Copy link
Contributor Author

@bdewater bdewater commented Aug 23, 2018

@simonoff like I mentioned the test failures seem unrelated to this change - can you try to rebuild please?

Edit: Jruby is failing on master still.

bdewater added 2 commits Jul 1, 2018
Small refactor along the way to centralize destination handling when no explicit path is given and a potential malicious one from the zipfile is used
Not sure if the exception is the right way to go
@bdewater bdewater force-pushed the bdewater:fix-cve-2018-1000544 branch from d68fbd2 to 8e78311 Aug 23, 2018
@reedloden
Copy link

@reedloden reedloden commented Aug 25, 2018

This was just added to ruby-advisory-db, so would love for this PR to be finalized, landed, and released.

@vipulnsward
Copy link
Contributor

@vipulnsward vipulnsward commented Aug 26, 2018

I looked at why the jruby builds were failing. Its after an upgrade to 9.2 affecting the crc32 checksum in Encryption tests.
We can ignore failures on JRuby, since its a difference in MRI and JRuby implementation for now.

@bdewater
Copy link
Contributor Author

@bdewater bdewater commented Aug 26, 2018

Thanks @vipulnsward - I've pulled your commit from #375 in to get this PR green.

@jdleesmiller
Copy link
Member

@jdleesmiller jdleesmiller commented Aug 26, 2018

Based on #371 (comment) and #371 (comment) I added tests for https://github.com/jwilk/path-traversal-samples

Tests are in: jdleesmiller@9c468f3

Good news: most pass.

Bad news: two don't pass: test_directory_symlink and test_two_directory_symlinks_b:

  1) Failure:
PathTraversalTest#test_two_directory_symlinks_b [/Users/john/ex/rubyzip/test/path_traversal_test.rb:85]:
Expected false to be truthy.

  2) Failure:
PathTraversalTest#test_directory_symlink [/Users/john/ex/rubyzip/test/path_traversal_test.rb:65]:
Expected false to be truthy.

I have not yet attempted to fix the bugs, and I'm not sure I know enough about this library to do that, but I thought I should at least report the test results.

Edit: Tried out a (rather drastic) fix in #376

david-a-wheeler added a commit to coreinfrastructure/best-practices-badge that referenced this pull request Aug 28, 2018
Ignore CVE-2018-1000544 (a vulnerability in rubyzip).
It does not affect production. See:
#1222
rubyzip/rubyzip#371
https://nvd.nist.gov/vuln/detail/CVE-2018-1000544

Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
This was referenced Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

10 participants