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

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.

@coveralls
Copy link

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 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
Copy link
Contributor Author

bdewater commented Jul 1, 2018

CI failures are unrelated (JRuby installation 404s)

Copy link

@JackMc JackMc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{../..}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 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)/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@zeha
Copy link

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 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

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

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

@bdewater
Copy link
Contributor Author

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.

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
@reedloden
Copy link

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

@vipulnsward
Copy link
Contributor

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 commented Aug 26, 2018

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

@jdleesmiller
Copy link
Member

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>
slonopotamus added a commit to slonopotamus/kindlegen that referenced this pull request Dec 22, 2019
unzipping was broken due to fixes for CVE-2018-1000544 in rubyzip: [1], [2].

Also, see [3].

Fixes tdtds#32.

[1]: rubyzip/rubyzip#371
[2]: rubyzip/rubyzip#376
[3]: rubyzip/rubyzip#354
slonopotamus added a commit to asciidoctor/asciidoctor-epub3 that referenced this pull request Mar 12, 2020
Unzipping was broken due to fixes for CVE-2018-1000544 in rubyzip: [1], [2].

Also, see [3].

[1]: rubyzip/rubyzip#371
[2]: rubyzip/rubyzip#376
[3]: rubyzip/rubyzip#354
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
Development

Successfully merging this pull request may close these issues.

Several directory traversal vulnerabilities
10 participants