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

Zip Path Traversal vulnerability #256

Closed
pwntester opened this issue Sep 4, 2018 · 0 comments
Closed

Zip Path Traversal vulnerability #256

pwntester opened this issue Sep 4, 2018 · 0 comments
Labels

Comments

@pwntester
Copy link

Hi,

The unzip APIs in better-files are vulnerable to a Zip entry path manipulation (see: https://snyk.io/research/zip-slip-vulnerability) . The library fails to check that the extracted file is going to be created under the destination folder.

A possible fix involves checking the normalized path of the final extracted file name and check that it starts with the destination path:

String canonicalDestinationDirPath = destinationDir.getCanonicalPath();
File destinationfile = new File(destinationDir, e.getName());
String canonicalDestinationFile = destinationfile.getCanonicalPath();
if (!canonicalDestinationFile.startsWith(canonicalDestinationDirPath + File.separator)) {
   throw new ArchiverException("Entry is outside of the target dir: " + e.getName());
}

Cheers,
A

@pathikrit pathikrit added the bug label Sep 4, 2018
arteme pushed a commit to arteme/better-files that referenced this issue Mar 8, 2024
* Fix else-logic error in File.unzipTo;
* Fix test for issue 624 by creating a file structure safe for unpacking
  provided ZIP file;
arteme pushed a commit to arteme/better-files that referenced this issue Mar 8, 2024
* Fix else-logic error in File.unzipTo;
* Fix test for issue 624 by creating a file structure safe for unpacking
  provided ZIP file;
pathikrit added a commit that referenced this issue Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants