Skip to content

Commit 88e77ad

Browse files
committed
False positive test case
1 parent 37d5c69 commit 88e77ad

File tree

1 file changed

+15
-0
lines changed
  • csharp/ql/test/query-tests/Security Features/CWE-022/ZipSlip

1 file changed

+15
-0
lines changed

csharp/ql/test/query-tests/Security Features/CWE-022/ZipSlip/ZipSlip.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,20 @@ static void Main(string[] args)
216216
}
217217
}
218218
}
219+
220+
/**
221+
* Negative - dangerous path terminates early due to exception thrown by guarded condition.
222+
*/
223+
static void fp_throw(ZipArchive archive, string root){
224+
foreach (var entry in archive.Entries){
225+
string destinationOnDisk = Path.GetFullPath(Path.Combine(root, entry.FullName));
226+
string fullRoot = Path.GetFullPath(root + Path.DirectorySeparatorChar);
227+
if (!destinationOnDisk.StartsWith(fullRoot)){
228+
throw new Exception("Entry is outside of target directory. There may have been some directory traversal sequences in filename.");
229+
}
230+
// NEGATIVE, above exception short circuits on invalid input by path traversal.
231+
entry.ExtractToFile(destinationOnDisk, true);
232+
}
233+
}
219234
}
220235
}

0 commit comments

Comments
 (0)