Skip to content

Commit 1029f04

Browse files
committed
Python: TarSlip sanitizer: handle not
1 parent 3c317ed commit 1029f04

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,16 @@ class TarFileInfoSanitizer extends Sanitizer {
124124
/** The test `if <path_sanitizing_test>:` clears taint on its `false` edge. */
125125
override predicate sanitizingEdge(TaintKind taint, PyEdgeRefinement test) {
126126
taint instanceof TarFileInfo and
127-
path_sanitizing_test(test.getTest()) and
128-
test.getSense() = false
127+
clears_taint_on_false_edge(test.getTest(), test.getSense())
128+
}
129+
130+
private predicate clears_taint_on_false_edge(ControlFlowNode test, boolean sense) {
131+
path_sanitizing_test(test) and
132+
sense = false
133+
or
134+
// handle `not` (also nested)
135+
test.(UnaryExprNode).getNode().getOp() instanceof Not and
136+
clears_taint_on_false_edge(test.(UnaryExprNode).getOperand(), sense.booleanNot())
129137
}
130138
}
131139

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@ edges
2121
| tarslip.py:57:1:57:17 | tarfile.entry | tarslip.py:59:21:59:25 | tarfile.entry |
2222
| tarslip.py:57:14:57:16 | tarfile.open | tarslip.py:57:1:57:17 | tarfile.entry |
2323
| 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 |
3024
#select
3125
| 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 |
3226
| 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 |
3327
| 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 |
3428
| 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 |
3529
| 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/") # TODO: FP
68+
tar.extract(entry, "/tmp/unpack/")

0 commit comments

Comments
 (0)