Skip to content

Commit 2d637e1

Browse files
committed
Python: Add more tarslip examples
1 parent c94582a commit 2d637e1

File tree

1 file changed

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

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,19 @@ def safemembers(members):
5050

5151
tar = tarfile.open(unsafe_filename_tar)
5252
tar.extractall(members=safemembers(tar))
53+
54+
55+
# Wrong sanitizer (is missing not)
56+
tar = tarfile.open(unsafe_filename_tar)
57+
for entry in tar:
58+
if os.path.isabs(entry.name) or ".." in entry.name:
59+
tar.extract(entry, "/tmp/unpack/") # TODO: FN
60+
61+
62+
# OK Sanitized using not
63+
tar = tarfile.open(unsafe_filename_tar)
64+
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.
67+
if not os.path.isabs(entry.name):
68+
tar.extract(entry, "/tmp/unpack/")

0 commit comments

Comments
 (0)