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: fail when trying to extract outside of dest dir #87

Conversation

odinn1984
Copy link

This PR is meant to fix an arbitrary file write vulnerability, that can be achieved using a specially crafted zip archive, that holds path traversal filenames. When the filename gets concatenated to the target extraction directory, the final path ends up outside of the target folder.

A sample malicious zip file named zip-slip.zip (see this gist) was used, and when running the code below, resulted in the creation of /tmp/evil.txt outside of the intended /tmp/safe target.

File testZip = new File("zip-slip.zip");
File targetDirectory = new File("/tmp/safedir");
    
ZipUnArchiver zu = getZipUnArchiver( testZip );
zu.extract( "", targetDirectory );

There are various possible ways to avoid this issue, some include checking for .. (dot dot) characters in the filename, but the best solution in our opinion is to check if the final target filename, starts with the target folder (after both are resolved to their absolute path).

Stay secure,
Snyk Team

A well crafted zip file may cause the code to extract outside of the destination dir.
This PR fails when that happens so that no unexpected behaviour happens.
@khmarbaise khmarbaise self-requested a review May 6, 2018 11:19
@khmarbaise khmarbaise added this to the 3.6.0 milestone May 6, 2018
@khmarbaise khmarbaise merged commit f8f4233 into codehaus-plexus:master May 6, 2018
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