Skip to content

Commit a8c14ed

Browse files
Update zipslip_bad.py
1 parent ddba3b7 commit a8c14ed

File tree

1 file changed

+11
-10
lines changed
  • python/ql/test/experimental/query-tests/Security/CWE-022

1 file changed

+11
-10
lines changed

python/ql/test/experimental/query-tests/Security/CWE-022/zipslip_bad.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,30 @@ def unzip(filename):
99
#BAD : This could write any file on the filesystem.
1010
for entry in zipf:
1111
shutil.move(entry, "/tmp/unpack/")
12-
12+
1313
def unzip1(filename):
1414
with gzip.open(filename) as zipf:
1515
#BAD : This could write any file on the filesystem.
1616
for entry in zipf:
1717
shutil.copy2(entry, "/tmp/unpack/")
18-
18+
1919
def unzip2(filename):
2020
with bz2.open(filename) as zipf:
2121
#BAD : This could write any file on the filesystem.
2222
for entry in zipf:
2323
shutil.copyfile(entry, "/tmp/unpack/")
24-
24+
2525
def unzip3(filename):
26-
with zipfile.ZipFile(filename) as zipf:
26+
zf = zipfile.ZipFile(filename)
27+
filelist = zf.namelist()
2728
#BAD : This could write any file on the filesystem.
28-
for entry in zipf:
29+
for filename in filelist:
2930
shutil.copy(entry, "/tmp/unpack/")
3031

3132
def unzip4(filename):
32-
with zipfile.ZipFile(filename) as zipf:
33-
for entry in zipf:
34-
with open(entry, 'wb') as dstfile:
35-
shutil.copyfileobj(zipf, dstfile)
36-
33+
zf = zipfile.ZipFile(filename)
34+
filelist = zf.namelist()
35+
for filename in filelist:
36+
with zf.open(filename) as srcf:
37+
shutil.copyfileobj(srcf, dstfile)
3738

0 commit comments

Comments
 (0)