File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
powershell/ql/test/query-tests/security/cwe-022 Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ edges
2+ subpaths
3+ #select
Original file line number Diff line number Diff line change 1+ queries/security/cwe-022/ZipSlip.ql
You can’t perform that action at this time.
0 commit comments