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

Skip to content

Commit d0081df

Browse files
committed
Python: Attempt at taint step for list.append/set.add
1 parent af20c3e commit d0081df

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ predicate containerStep(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeTo) {
177177
"values", "items", "get", "popitem"] and
178178
call.getFunction().(AttrNode).getObject(name) = nodeFrom.getNode()
179179
)
180+
or
181+
// list.append, set.add
182+
// NOTE: this currently doesn't work, since there are no PostUpdateNodes
183+
exists(CallNode call, string name |
184+
name in ["append", "add"] and
185+
call.getFunction().(AttrNode).getObject(name) =
186+
nodeTo.(PostUpdateNode).getPreUpdateNode().(DataFlow::CfgNode).getNode() and
187+
call.getArg(0) = nodeFrom.getNode()
188+
)
180189
}
181190

182191
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
| collections_.py:137 | fail | list_index_aug_assign | my_list |
5050
| collections_.py:144 | ok | list_append | my_list |
5151
| collections_.py:147 | fail | list_append | my_list |
52+
| collections_.py:154 | ok | set_add | my_set |
53+
| collections_.py:157 | fail | set_add | my_set |
5254
| json_.py:26 | ok | test | json.dumps(..) |
5355
| json_.py:27 | ok | test | json.loads(..) |
5456
| json_.py:34 | fail | test | tainted_filelike |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ def list_append():
147147
ensure_tainted(my_list)
148148

149149

150+
def set_add():
151+
tainted_string = TAINTED_STRING
152+
my_set = {"safe"}
153+
154+
ensure_not_tainted(my_set)
155+
156+
my_set.add(tainted_string)
157+
ensure_tainted(my_set)
158+
159+
150160
# Make tests runable
151161

152162
test_construction()
@@ -158,3 +168,4 @@ def list_append():
158168
list_index_assign()
159169
list_index_aug_assign()
160170
list_append()
171+
set_add()

0 commit comments

Comments
 (0)