File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
csharp/ql/test/query-tests/Security Features/CWE-022/ZipSlip Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -216,5 +216,20 @@ static void Main(string[] args)
216
216
}
217
217
}
218
218
}
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
+ }
219
234
}
220
235
}
You can’t perform that action at this time.
0 commit comments