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

Skip to content

Commit 32f9d30

Browse files
committed
Python: Add syntactic taint steps for json methods
1 parent 41e24ae commit 32f9d30

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ predicate localAdditionalTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeT
3030
subscriptStep(nodeFrom, nodeTo)
3131
or
3232
stringManipulation(nodeFrom, nodeTo)
33+
or
34+
jsonStep(nodeFrom, nodeTo)
3335
}
3436

3537
/**
@@ -123,3 +125,13 @@ predicate stringManipulation(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeT
123125
// TODO: Handle os.path.join
124126
// TODO: Handle functions in https://docs.python.org/3/library/binascii.html
125127
}
128+
129+
/**
130+
* Holds if taint can flow from `nodeFrom` to `nodeTo` with a step related to JSON encoding/decoding.
131+
*/
132+
predicate jsonStep(DataFlow::CfgNode nodeFrom, DataFlow::CfgNode nodeTo) {
133+
exists(CallNode call | call = nodeTo.getNode() |
134+
call.getFunction().(AttrNode).getObject(["load", "loads", "dumps"]).(NameNode).getId() = "json" and
135+
call.getArg(0) = nodeFrom.getNode()
136+
)
137+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
| collections.py:103 | fail | test_defaultdict | tainted_default_dict.copy() |
3636
| collections.py:106 | fail | test_defaultdict | v |
3737
| collections.py:108 | fail | test_defaultdict | v |
38-
| json.py:26 | fail | test | json.dumps(..) |
39-
| json.py:27 | fail | test | json.loads(..) |
38+
| json.py:26 | ok | test | json.dumps(..) |
39+
| json.py:27 | ok | test | json.loads(..) |
4040
| json.py:34 | fail | test | tainted_filelike |
4141
| json.py:35 | fail | test | json.load(..) |
4242
| json.py:48 | fail | non_syntacical | dumps(..) |

0 commit comments

Comments
 (0)