-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed potential security vulnerability reported by Snyk Security Rese…
…arch Team This is an arbitrary file write vulnerability, that can be achieved using a specially crafted zip archive, that holds path traversal filenames. So when the filename gets concatenated to the target extraction directory, the final path ends up outside of the target folder.
- Loading branch information
Toomas Romer
committed
Apr 26, 2018
1 parent
d1c4077
commit 759b72f
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/org/zeroturnaround/zip/DirectoryTraversalMaliciousTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.zeroturnaround.zip; | ||
|
||
/** | ||
* Copyright (C) 2012 ZeroTurnaround LLC <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import java.io.File; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class DirectoryTraversalMaliciousTest extends TestCase { | ||
/* | ||
* This is the contents of the file. There is one evil file that tries to get out of the | ||
* target. | ||
* | ||
* $ unzip -t zip-slip.zip | ||
* Archive: zip-slip.zip | ||
* testing: good.txt OK | ||
* testing: ../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../tmp/evil.txt OK | ||
* No errors detected in compressed data of zip-slip.zip. | ||
*/ | ||
private static final File badFile = new File("src/test/resources/zip-malicious-traversal.zip"); | ||
private static final File badFileBackslashes = new File("src/test/resources/zip-malicious-traversal-backslashes.zip"); | ||
|
||
public void testUnpackDoesntLeaveTarget() throws Exception { | ||
File file = File.createTempFile("temp", null); | ||
File tmpDir = file.getParentFile(); | ||
|
||
try { | ||
ZipUtil.unpack(badFile, tmpDir); | ||
fail(); | ||
} | ||
catch (ZipException e) { | ||
assertTrue(true); | ||
} | ||
} | ||
|
||
public void testUnwrapDoesntLeaveTarget() throws Exception { | ||
File file = File.createTempFile("temp", null); | ||
File tmpDir = file.getParentFile(); | ||
|
||
try { | ||
ZipUtil.iterate(badFileBackslashes, new ZipUtil.BackslashUnpacker(tmpDir)); | ||
fail(); | ||
} | ||
catch (ZipException e) { | ||
assertTrue(true); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.