Skip to content

Commit cafbd98

Browse files
Update zipslip_bad.py
1 parent f364e41 commit cafbd98

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

python/ql/src/experimental/Security/CWE-022/zipslip_bad.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import shutil
33

44
def unzip(filename):
5-
with zipfile.ZipFile(filename) as zipf:
5+
with tarfile.open(filename) as zipf:
66
#BAD : This could write any file on the filesystem.
77
for entry in zipf:
8-
shutil.copy(entry, "/tmp/unpack/")
8+
shutil.copyfile(entry, "/tmp/unpack/")
99

10-
def unzip1(filename):
11-
with zipfile.ZipFile(filename) as zipf:
12-
for entry in zipf:
13-
with open(entry, 'wb') as dstfile:
14-
shutil.copyfileobj(zipf, dstfile)
10+
def unzip4(filename):
11+
zf = zipfile.ZipFile(filename)
12+
filelist = zf.namelist()
13+
for filename in filelist:
14+
with zf.open(filename) as srcf:
15+
shutil.copyfileobj(srcf, dstfile)
16+

0 commit comments

Comments
 (0)