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

Skip to content

Commit e2a89aa

Browse files
committed
Python: Add additional taint steps for copy
deepcopy was already handled somehow, don't really know how :D
1 parent b974dad commit e2a89aa

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ predicate localAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeT
3434
jsonStep(nodeFrom, nodeTo)
3535
or
3636
containerStep(nodeFrom, nodeTo)
37+
or
38+
copyStep(nodeFrom, nodeTo)
3739
}
3840

3941
/**
@@ -172,3 +174,19 @@ predicate containerStep(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeTo) {
172174
call.getFunction().(AttrNode).getObject(name) = nodeFrom.getNode()
173175
)
174176
}
177+
178+
179+
/**
180+
* Holds if taint can flow from `nodeFrom` to `nodeTo` with a step related to copying.
181+
*/
182+
predicate copyStep(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeTo) {
183+
exists(CallNode call | call = nodeTo.getNode() |
184+
// Fully qualified: copy.copy, copy.deepcopy
185+
(
186+
call.getFunction().(NameNode).getId() in ["copy", "deepcopy"]
187+
or
188+
call.getFunction().(AttrNode).getObject("copy").(NameNode).getId() in ["copy", "deepcopy"]
189+
) and
190+
call.getArg(0) = nodeFrom.getNode()
191+
)
192+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
| collections.py:53 | ok | test_access | reversed(..) |
1919
| collections.py:54 | ok | test_access | iter(..) |
2020
| collections.py:55 | ok | test_access | next(..) |
21-
| collections.py:56 | fail | test_access | copy(..) |
21+
| collections.py:56 | ok | test_access | copy(..) |
2222
| collections.py:57 | ok | test_access | deepcopy(..) |
2323
| collections.py:61 | fail | test_access | a |
2424
| collections.py:61 | fail | test_access | b |

0 commit comments

Comments
 (0)