mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
JS: Add o[o.length] = y taint step
This commit is contained in:
@@ -584,22 +584,26 @@ module TaintTracking {
|
||||
|
||||
/**
|
||||
* A taint propagating data flow edge for assignments of the form `o[k] = v`, where
|
||||
* `k` is not a constant and `o` refers to some object literal; in this case, we consider
|
||||
* taint to flow from `v` to that object literal.
|
||||
* one of the following holds:
|
||||
*
|
||||
* The rationale for this heuristic is that if properties of `o` are accessed by
|
||||
* computed (that is, non-constant) names, then `o` is most likely being treated as
|
||||
* a map, not as a real object. In this case, it makes sense to consider the entire
|
||||
* map to be tainted as soon as one of its entries is.
|
||||
* - `k` is not a constant and `o` refers to some object literal. The rationale
|
||||
* here is that `o` is most likely being used like a dictionary object.
|
||||
*
|
||||
* - `k` refers to `o.length`, that is, the assignment is of form `o[o.length] = v`.
|
||||
* In this case, the assignment behaves like `o.push(v)`.
|
||||
*/
|
||||
private class DictionaryTaintStep extends SharedTaintStep {
|
||||
private class ComputedPropWriteTaintStep extends SharedTaintStep {
|
||||
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
|
||||
exists(AssignExpr assgn, IndexExpr idx, DataFlow::ObjectLiteralNode obj |
|
||||
exists(AssignExpr assgn, IndexExpr idx, DataFlow::SourceNode obj |
|
||||
assgn.getTarget() = idx and
|
||||
obj.flowsToExpr(idx.getBase()) and
|
||||
not exists(idx.getPropertyName()) and
|
||||
pred = DataFlow::valueNode(assgn.getRhs()) and
|
||||
succ = obj
|
||||
|
|
||||
obj instanceof DataFlow::ObjectLiteralNode
|
||||
or
|
||||
obj.getAPropertyRead("length").flowsToExpr(idx.getPropertyNameExpr())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user