Skip to content

Commit dcfc9a8

Browse files
committed
Python: TarSlip sanitizer: explain tests with not
It was a bit confusing what was meant before
1 parent 1029f04 commit dcfc9a8

File tree

1 file changed

+16
-2
lines changed
  • python/ql/test/query-tests/Security/CWE-022

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,21 @@ def safemembers(members):
6262
# OK Sanitized using not
6363
tar = tarfile.open(unsafe_filename_tar)
6464
for entry in tar:
65-
# using `if not (os.path.isabs(entry.name) or ".." in entry.name):`
66-
# would make the sanitizer work, but for the wrong reasons since out library is a bit broken.
65+
if not (os.path.isabs(entry.name) or ".." in entry.name):
66+
tar.extract(entry, "/tmp/unpack/")
67+
68+
# The following two variants are included by purpose, since by default there is a
69+
# difference in handling `not x` and `not (x or False)` when overriding
70+
# Sanitizer.sanitizingEdge. We want to ensure we handle both consistently.
71+
72+
# Not reported, although vulnerable to '..'
73+
tar = tarfile.open(unsafe_filename_tar)
74+
for entry in tar:
75+
if not (os.path.isabs(entry.name) or False):
76+
tar.extract(entry, "/tmp/unpack/")
77+
78+
# Not reported, although vulnerable to '..'
79+
tar = tarfile.open(unsafe_filename_tar)
80+
for entry in tar:
6781
if not os.path.isabs(entry.name):
6882
tar.extract(entry, "/tmp/unpack/")

0 commit comments

Comments
 (0)