Skip to content

Commit 1e50f76

Browse files
committed
Fix ZipSlip bug found by LGTM.com
The unsanitized path of a zip archive entry, which may contain '..', was used directly to resolve the destination path for the files being unzipped. Although the prefix of the path was checked against `sourceFolder`, there could be ".." path segments after that. Extracting files from a malicious archive without validating that the destination file path is within the destination directory can cause files outside the destination directory to be overwritten.
1 parent 8174168 commit 1e50f76

File tree

1 file changed

+3
-0
lines changed
  • runner/src/main/java/com/codingame/gameengine/runner

1 file changed

+3
-0
lines changed

runner/src/main/java/com/codingame/gameengine/runner/Renderer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ private static List<Path> exportViewToWorkingDir(String sourceFolder, Path targe
139139
String entryTail = name.substring(sourceFolder.length());
140140

141141
File f = new File(targetFolder + File.separator + entryTail);
142+
if (!f.toPath().normalize().startsWith(targetFolder)) {
143+
throw new IOException("Zip entry contained path traversal");
144+
}
142145
if (entry.isDirectory()) {
143146
f.mkdir();
144147
} else {

0 commit comments

Comments
 (0)