Fix zip slip vulnerability (CCSDK-3376) 25/122725/2
authorJonathan Platt <jonathan.platt@att.com>
Mon, 19 Jul 2021 16:20:41 +0000 (12:20 -0400)
committerJonathan Platt <jonathan.platt@att.com>
Tue, 20 Jul 2021 12:19:19 +0000 (08:19 -0400)
Check and enforce canonical destination path of new file to resolve zip
slip vulnerability in 'DaeximOffsiteBackupProvider.java'

Issue-ID: CCSDK-3376
Signed-off-by: Jonathan Platt <jonathan.platt@att.com>
Change-Id: I249752d7a8bb1a8075502b5130f94c32986ab8ee

northbound/daexim-offsite-backup/provider/src/main/java/org/onap/ccsdk/sli/northbound/daeximoffsitebackup/DaeximOffsiteBackupProvider.java

index 3d32c7d..8abefb7 100755 (executable)
@@ -333,6 +333,10 @@ public class DaeximOffsiteBackupProvider implements AutoCloseable, DaeximOffsite
         while(zipEntry != null){
             String fileName = zipEntry.getName();
             File newFile = new File(DAEXIM_DIR + fileName);
+            // To remediate zip slip vulnerability, ensure file has the expected canonical path
+            if (!newFile.getCanonicalPath().startsWith(DAEXIM_DIR)) {
+                throw new IOException("Entry is outside of the target directory");
+            }
             FileOutputStream fos = new FileOutputStream(newFile);
             int len;
             while ((len = zis.read(bytes)) > 0) {