Skip to content

Commit

Permalink
Merge pull request from GHSA-m88m-crr9-jvqq
Browse files Browse the repository at this point in the history
* Fix zip slip vulnerability in project import command

* Add zip-slip.tar test resource
  • Loading branch information
wetneb committed Jul 17, 2023
1 parent 15a0295 commit e9c1e65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main/src/com/google/refine/io/FileProjectManager.java
Expand Up @@ -169,6 +169,9 @@ protected void untar(File destDir, InputStream inputStream) throws IOException {

while ((tarEntry = tin.getNextTarEntry()) != null) {
File destEntry = new File(destDir, tarEntry.getName());
if (!destEntry.toPath().normalize().startsWith(destDir.toPath().normalize())) {
throw new IllegalArgumentException("Zip archives with files escaping their root directory are not allowed.");
}
File parent = destEntry.getParentFile();

if (!parent.exists()) {
Expand Down
Binary file added main/tests/data/zip-slip.tar
Binary file not shown.
Expand Up @@ -150,4 +150,19 @@ public void metaFileUpdateTest() throws GetProjectIDException, InterruptedExcept
assertEquals(timeBeforeB, timeAfterB);
assertNotEquals(timeBeforeA, timeAfterA);
}

@Test
public void testUntarZipSlip() throws IOException {
FileProjectManager manager = new FileProjectManagerStub(workspaceDir);

File tempDir = TestUtils.createTempDirectory("openrefine-project-import-zip-slip-test");
try {
File subDir = new File(tempDir, "dest");
InputStream stream = FileProjectManagerTests.class.getClassLoader().getResourceAsStream("zip-slip.tar");

assertThrows(IllegalArgumentException.class, () -> manager.untar(subDir, stream));
} finally {
tempDir.delete();
}
}
}

0 comments on commit e9c1e65

Please sign in to comment.