Skip to content

Commit 3c317ed

Browse files
committed
Python: TarSlip sanitizer: only clear taint on false edge
maybe it was on purpose, will have to investigate FPs when query is good
1 parent 2d637e1 commit 3c317ed

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

python/ql/src/Security/CWE-022/TarSlip.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ class ExtractMembersSink extends TaintSink {
121121
class TarFileInfoSanitizer extends Sanitizer {
122122
TarFileInfoSanitizer() { this = "TarInfo sanitizer" }
123123

124+
/** The test `if <path_sanitizing_test>:` clears taint on its `false` edge. */
124125
override predicate sanitizingEdge(TaintKind taint, PyEdgeRefinement test) {
126+
taint instanceof TarFileInfo and
125127
path_sanitizing_test(test.getTest()) and
126-
taint instanceof TarFileInfo
128+
test.getSense() = false
127129
}
128130
}
129131

python/ql/test/query-tests/Security/CWE-022/TarSlip.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,22 @@ edges
1515
| tarslip.py:34:14:34:16 | tarfile.open | tarslip.py:34:1:34:17 | tarfile.entry |
1616
| tarslip.py:40:7:40:39 | tarfile.open | tarslip.py:41:24:41:26 | tarfile.open |
1717
| tarslip.py:40:7:40:39 | tarfile.open | tarslip.py:41:24:41:26 | tarfile.open |
18+
| tarslip.py:56:7:56:39 | tarfile.open | tarslip.py:57:14:57:16 | tarfile.open |
19+
| tarslip.py:56:7:56:39 | tarfile.open | tarslip.py:57:14:57:16 | tarfile.open |
20+
| tarslip.py:57:1:57:17 | tarfile.entry | tarslip.py:59:21:59:25 | tarfile.entry |
21+
| tarslip.py:57:1:57:17 | tarfile.entry | tarslip.py:59:21:59:25 | tarfile.entry |
22+
| tarslip.py:57:14:57:16 | tarfile.open | tarslip.py:57:1:57:17 | tarfile.entry |
23+
| tarslip.py:57:14:57:16 | tarfile.open | tarslip.py:57:1:57:17 | tarfile.entry |
24+
| tarslip.py:63:7:63:39 | tarfile.open | tarslip.py:64:14:64:16 | tarfile.open |
25+
| tarslip.py:63:7:63:39 | tarfile.open | tarslip.py:64:14:64:16 | tarfile.open |
26+
| tarslip.py:64:1:64:17 | tarfile.entry | tarslip.py:68:21:68:25 | tarfile.entry |
27+
| tarslip.py:64:1:64:17 | tarfile.entry | tarslip.py:68:21:68:25 | tarfile.entry |
28+
| tarslip.py:64:14:64:16 | tarfile.open | tarslip.py:64:1:64:17 | tarfile.entry |
29+
| tarslip.py:64:14:64:16 | tarfile.open | tarslip.py:64:1:64:17 | tarfile.entry |
1830
#select
1931
| tarslip.py:13:1:13:3 | tar | tarslip.py:12:7:12:39 | tarfile.open | tarslip.py:13:1:13:3 | tarfile.open | Extraction of tarfile from $@ | tarslip.py:12:7:12:39 | Attribute() | a potentially untrusted source |
2032
| tarslip.py:18:17:18:21 | entry | tarslip.py:16:7:16:39 | tarfile.open | tarslip.py:18:17:18:21 | tarfile.entry | Extraction of tarfile from $@ | tarslip.py:16:7:16:39 | Attribute() | a potentially untrusted source |
2133
| tarslip.py:37:17:37:21 | entry | tarslip.py:33:7:33:39 | tarfile.open | tarslip.py:37:17:37:21 | tarfile.entry | Extraction of tarfile from $@ | tarslip.py:33:7:33:39 | Attribute() | a potentially untrusted source |
2234
| tarslip.py:41:24:41:26 | tar | tarslip.py:40:7:40:39 | tarfile.open | tarslip.py:41:24:41:26 | tarfile.open | Extraction of tarfile from $@ | tarslip.py:40:7:40:39 | Attribute() | a potentially untrusted source |
35+
| tarslip.py:59:21:59:25 | entry | tarslip.py:56:7:56:39 | tarfile.open | tarslip.py:59:21:59:25 | tarfile.entry | Extraction of tarfile from $@ | tarslip.py:56:7:56:39 | Attribute() | a potentially untrusted source |
36+
| tarslip.py:68:21:68:25 | entry | tarslip.py:63:7:63:39 | tarfile.open | tarslip.py:68:21:68:25 | tarfile.entry | Extraction of tarfile from $@ | tarslip.py:63:7:63:39 | Attribute() | a potentially untrusted source |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def safemembers(members):
5656
tar = tarfile.open(unsafe_filename_tar)
5757
for entry in tar:
5858
if os.path.isabs(entry.name) or ".." in entry.name:
59-
tar.extract(entry, "/tmp/unpack/") # TODO: FN
59+
tar.extract(entry, "/tmp/unpack/")
6060

6161

6262
# OK Sanitized using not
@@ -65,4 +65,4 @@ def safemembers(members):
6565
# using `if not (os.path.isabs(entry.name) or ".." in entry.name):`
6666
# would make the sanitizer work, but for the wrong reasons since out library is a bit broken.
6767
if not os.path.isabs(entry.name):
68-
tar.extract(entry, "/tmp/unpack/")
68+
tar.extract(entry, "/tmp/unpack/") # TODO: FP

0 commit comments

Comments
 (0)