Skip to content

Commit 6697dd1

Browse files
committed
rewrite some expression based predicates in TaintTracking.qll
1 parent b4968eb commit 6697dd1

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,16 @@ module TaintTracking {
546546
*/
547547
private class ComputedPropWriteTaintStep extends SharedTaintStep {
548548
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
549-
exists(AssignExpr assgn, IndexExpr idx, DataFlow::SourceNode obj |
550-
assgn.getTarget() = idx and
551-
obj.flowsToExpr(idx.getBase()) and
552-
not exists(idx.getPropertyName()) and
553-
pred = DataFlow::valueNode(assgn.getRhs()) and
549+
exists(DataFlow::PropWrite assgn, DataFlow::SourceNode obj |
550+
not exists(assgn.getPropertyName()) and
551+
not assgn.getWriteNode() instanceof Property and // not a write inside an object literal
552+
pred = assgn.getRhs() and
553+
assgn = obj.getAPropertyWrite() and
554554
succ = obj
555555
|
556556
obj instanceof DataFlow::ObjectLiteralNode
557557
or
558-
obj.getAPropertyRead("length").flowsToExpr(idx.getPropertyNameExpr())
558+
obj.getAPropertyRead("length").flowsToExpr(assgn.getPropertyNameExpr())
559559
)
560560
}
561561
}
@@ -580,8 +580,8 @@ module TaintTracking {
580580
override predicate stringManipulationStep(DataFlow::Node pred, DataFlow::Node target) {
581581
exists(DataFlow::ValueNode succ | target = succ |
582582
// string operations that propagate taint
583-
exists(string name | name = succ.getAstNode().(MethodCallExpr).getMethodName() |
584-
pred.asExpr() = succ.getAstNode().(MethodCallExpr).getReceiver() and
583+
exists(string name | name = succ.(DataFlow::MethodCallNode).getMethodName() |
584+
pred = succ.(DataFlow::MethodCallNode).getReceiver() and
585585
(
586586
// sorted, interesting, properties of String.prototype
587587
name =
@@ -600,7 +600,7 @@ module TaintTracking {
600600
name = "join"
601601
)
602602
or
603-
exists(int i | pred.asExpr() = succ.getAstNode().(MethodCallExpr).getArgument(i) |
603+
exists(int i | pred = succ.(DataFlow::MethodCallNode).getArgument(i) |
604604
name = "concat"
605605
or
606606
name = ["replace", "replaceAll"] and i = 1
@@ -615,10 +615,10 @@ module TaintTracking {
615615
)
616616
or
617617
// String.fromCharCode and String.fromCodePoint
618-
exists(int i, MethodCallExpr mce |
619-
mce = succ.getAstNode() and
620-
pred.asExpr() = mce.getArgument(i) and
621-
(mce.getMethodName() = "fromCharCode" or mce.getMethodName() = "fromCodePoint")
618+
exists(int i, DataFlow::MethodCallNode mcn |
619+
mcn = succ and
620+
pred = mcn.getArgument(i) and
621+
mcn.getMethodName() = ["fromCharCode", "fromCodePoint"]
622622
)
623623
or
624624
// `(encode|decode)URI(Component)?` propagate taint
@@ -744,11 +744,11 @@ module TaintTracking {
744744
* the parameters in `input`.
745745
*/
746746
predicate isUrlSearchParams(DataFlow::SourceNode params, DataFlow::Node input) {
747-
exists(DataFlow::GlobalVarRefNode urlSearchParams, NewExpr newUrlSearchParams |
747+
exists(DataFlow::GlobalVarRefNode urlSearchParams, DataFlow::NewNode newUrlSearchParams |
748748
urlSearchParams.getName() = "URLSearchParams" and
749-
newUrlSearchParams = urlSearchParams.getAnInstantiation().asExpr() and
750-
params.asExpr() = newUrlSearchParams and
751-
input.asExpr() = newUrlSearchParams.getArgument(0)
749+
newUrlSearchParams = urlSearchParams.getAnInstantiation() and
750+
params = newUrlSearchParams and
751+
input = newUrlSearchParams.getArgument(0)
752752
)
753753
}
754754

0 commit comments

Comments
 (0)