Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit efa2484

Browse files
committed
Python: Add taint test for os.path.join
Surprisingly the first two just worked, due to our very general handling of any `join` methods :D
1 parent aa6fad5 commit efa2484

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

python/ql/src/experimental/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ predicate stringManipulation(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeT
101101
nodeFrom.getNode() = object and
102102
method_name in ["partition", "rpartition", "rsplit", "split", "splitlines"]
103103
or
104-
// List[str] -> str
104+
// Iterable[str] -> str
105105
// TODO: check if these should be handled differently in regards to content
106106
method_name = "join" and
107107
nodeFrom.getNode() = call.getArg(0)

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/TestTaint.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@
137137
| test_string.py:143 | fail | binary_decode_encode | base64.decodestring(..) |
138138
| test_string.py:148 | fail | binary_decode_encode | quopri.encodestring(..) |
139139
| test_string.py:149 | fail | binary_decode_encode | quopri.decodestring(..) |
140+
| test_string.py:158 | ok | test_os_path_join | os.path.join(..) |
141+
| test_string.py:159 | ok | test_os_path_join | os.path.join(..) |
142+
| test_string.py:160 | fail | test_os_path_join | os.path.join(..) |
140143
| test_unpacking.py:16 | ok | unpacking | a |
141144
| test_unpacking.py:16 | ok | unpacking | b |
142145
| test_unpacking.py:16 | ok | unpacking | c |

python/ql/test/experimental/dataflow/tainttracking/defaultAdditionalTaintStep/test_string.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,22 @@ def binary_decode_encode():
150150
)
151151

152152

153+
def test_os_path_join():
154+
import os
155+
print("\n# test_os_path_join")
156+
ts = TAINTED_STRING
157+
ensure_tainted(
158+
os.path.join(ts, "foo", "bar"),
159+
os.path.join(ts),
160+
os.path.join("foo", "bar", ts),
161+
)
162+
163+
153164
# Make tests runable
154165

155166
str_operations()
156167
str_methods()
157168
non_syntactic()
158169
percent_fmt()
159170
binary_decode_encode()
171+
test_os_path_join()

0 commit comments

Comments
 (0)