Skip to content

Commit 8d3f6b8

Browse files
committed
PS: Add tests.
1 parent 9916bbb commit 8d3f6b8

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Add-Type -AssemblyName System.IO.Compression.FileSystem
2+
3+
$zip = [System.IO.Compression.ZipFile]::OpenRead("MyPath\to\archive.zip")
4+
5+
foreach ($entry in $zip.Entries) {
6+
$targetPath = Join-Path $extractPath $entry.FullName
7+
$fullTargetPath = [System.IO.Path]::GetFullPath($targetPath)
8+
9+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $fullTargetPath) # BAD [NOT DETECTED]
10+
}
11+
12+
foreach ($entry in $zip.Entries) {
13+
$targetPath = Join-Path $extractPath $entry.FullName
14+
$fullTargetPath = [System.IO.Path]::GetFullPath($targetPath)
15+
16+
$stream = [System.IO.File]::Open($fullTargetPath, 'Create') # BAD [NOT DETECTED]
17+
$entry.Open().CopyTo($stream)
18+
$stream.Close()
19+
}
20+
21+
foreach ($entry in $zip.Entries) {
22+
$targetPath = Join-Path $extractPath $entry.FullName
23+
$fullTargetPath = [System.IO.Path]::GetFullPath($targetPath)
24+
25+
$extractRoot = [System.IO.Path]::GetFullPath($extractPath)
26+
if ($fullTargetPath.StartsWith($extractRoot)) {
27+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $fullTargetPath) # GOOD
28+
}
29+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edges
2+
subpaths
3+
#select
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/security/cwe-022/ZipSlip.ql

0 commit comments

Comments
 (0)