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

Prevent arbitrary file overwrite via path traversal [CVE-2019-10743] #169

Closed
wants to merge 2 commits into from
Closed

Conversation

giuliocomi
Copy link
Contributor

This PR is meant to patch the current version 3.1.1 against Zip Slip attacks (https://github.com/snyk/zip-slip-vulnerability).

This issue and patch are part of the vulnerability disclosure program of Snyk (more info here https://snyk.io/docs/security/).

Brief summary: In April 2018 a pull request (#65) was made by Snyk's security researcher and was integrated in version 2.1. After the refactoring of the whole project in version 3.0 (November 2018) the security fix was undone, reintroducing therefore the vulnerability till now.
A security note in the current README (fea250a#diff-04c6e90faac2675aa89e2176d2eec7d8) suggests the 'users' to implement their own security control with Walkers but this approach might be error prone and introduce a new kind of security issue - TOCTOU race conditions - that may allow to bypass the proposed path traversal prevention with Walkers.
Furthermore, I strongly believe that a security check must be available by design and be transparent in its usage.

Special thanks to Karen Yavine Shemesh of Snyk's security team for her responsiveness and coordination of this disclosure.

@mholt
Copy link
Owner

mholt commented May 13, 2019

Thanks, but this will need test cases to prove it works before it will be considered, and the CI tests will need to pass as well.

the extraction process now continues with other files  by default even if there is a dot-dot filename, which is of course skipped.
The test evilarchives have been generated with following script:
https://github.com/giuliocomi/evilarchiver
Command:
$ mkdir safedir
$ touch security_test.txt safedir/safefile
$ python2 evilarchiver.py -e security_test.txt -n ../evilfile -s safedir/safefile
@giuliocomi
Copy link
Contributor Author

I have added some test cases in archiver_test.go.
For what regards the CI broken is due to test functions:

  • TestArchiveUnarchive
  • TestArchiveUnarchiveWithFolderPermissions
    that have failed from quite some time but are not correlated with the changes introduced by the security patch.

@giuliocomi giuliocomi changed the title Prevent arbitrary file overwrite via path traversal (Zip Slip attack) Prevent arbitrary file overwrite via path traversal [CVE-2019-10743] May 17, 2019
@ferhatelmas
Copy link

ferhatelmas commented Nov 13, 2019

I want to use this package in krew.dev to simplify archive download and unpack but this security issue is a show stopper.

If the walker was exposing path information, it could be done where it's used.

Is it possible to give a bump to this PR? Happy to help.

Until PR is in, I will go with header inspection.

return fmt.Errorf("illegal file path: %s", filename)
}
return nil
}

Choose a reason for hiding this comment

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

It seems this functionality is duplicated, better to extract to a separate function and call it.

Might be better to define it on struct{} and inline into formats.

@fergusstrange
Copy link

@ferhatelmas and @giuliocomi. I have reopened this in #203, rebased against master and with a few fixes to pass lint build.

Keen to get this in as I need the CVE closed for another project I am working on Embedded-Postgres

Let me know thoughts?

Also big thanks to @mholt for all the great work in this project already 👍

@coolaj86
Copy link
Collaborator

Hi @giuliocomi,

I've recently been given the almighty approver privileges and I'd like to get this pushed through.

I'm familiar with this CVE and how dangerous it is, and I've actually fixed it myself in a node library a while back.

I've reviewed the changes and they look great. Could you possibly rebase this on the current master? If so I'll approve and merge it right away, and I'll include it in the upcoming release.

@coolaj86
Copy link
Collaborator

Merged via #231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants