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

Skip to content

Commit afb160f

Browse files
committed
Python: Add additional taint steps for for-iteration
1 parent e2a89aa commit afb160f

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ predicate localAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeT
3636
containerStep(nodeFrom, nodeTo)
3737
or
3838
copyStep(nodeFrom, nodeTo)
39+
or
40+
forStep(nodeFrom, nodeTo)
3941
}
4042

4143
/**
@@ -190,3 +192,16 @@ predicate copyStep(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeTo) {
190192
call.getArg(0) = nodeFrom.getNode()
191193
)
192194
}
195+
196+
197+
/**
198+
* Holds if taint can flow from `nodeFrom` to `nodeTo` with a step related to `for`-iteration,
199+
* for example `for x in xs`, or `for x,y in points`.
200+
*/
201+
predicate forStep(DataFlow::CfgNode nodeFrom, DataFlow::EssaNode nodeTo) {
202+
exists(EssaNodeDefinition defn, For for |
203+
for.getTarget().getAChildNode*() = defn.getDefiningNode().getNode() and
204+
nodeTo.getVar() = defn and
205+
nodeFrom.getNode().getNode() = for.getIter()
206+
)
207+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
| unpacking.py:18 | fail | extended_unpacking | last |
1414
| unpacking.py:18 | fail | extended_unpacking | rest |
1515
| unpacking.py:23 | fail | also_allowed | a |
16-
| unpacking.py:31 | fail | also_allowed | b |
17-
| unpacking.py:31 | fail | also_allowed | c |
16+
| unpacking.py:31 | ok | also_allowed | b |
17+
| unpacking.py:31 | ok | also_allowed | c |
1818
| unpacking.py:39 | fail | nested | x |
1919
| unpacking.py:39 | fail | nested | xs |
2020
| unpacking.py:39 | fail | nested | ys |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
| collections.py:61 | fail | test_access | a |
2424
| collections.py:61 | fail | test_access | b |
2525
| collections.py:61 | fail | test_access | c |
26-
| collections.py:64 | fail | test_access | h |
27-
| collections.py:66 | fail | test_access | i |
26+
| collections.py:64 | ok | test_access | h |
27+
| collections.py:66 | ok | test_access | i |
2828
| collections.py:73 | ok | test_dict_access | tainted_dict["name"] |
2929
| collections.py:74 | ok | test_dict_access | tainted_dict.get(..) |
3030
| collections.py:75 | ok | test_dict_access | tainted_dict[x] |
3131
| collections.py:76 | ok | test_dict_access | tainted_dict.copy() |
32-
| collections.py:80 | fail | test_dict_access | v |
33-
| collections.py:82 | fail | test_dict_access | v |
32+
| collections.py:80 | ok | test_dict_access | v |
33+
| collections.py:82 | ok | test_dict_access | v |
3434
| collections.py:90 | fail | test_named_tuple | point[0] |
3535
| collections.py:91 | fail | test_named_tuple | point.x |
3636
| collections.py:95 | ok | test_named_tuple | point[1] |

0 commit comments

Comments
 (0)