Skip to content

Commit ca50889

Browse files
committed
rewrite some expression based predicates in TaintTracking.qll
1 parent ac454d8 commit ca50889

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
@@ -580,16 +580,16 @@ module TaintTracking {
580580
*/
581581
private class ComputedPropWriteTaintStep extends SharedTaintStep {
582582
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
583-
exists(AssignExpr assgn, IndexExpr idx, DataFlow::SourceNode obj |
584-
assgn.getTarget() = idx and
585-
obj.flowsToExpr(idx.getBase()) and
586-
not exists(idx.getPropertyName()) and
587-
pred = DataFlow::valueNode(assgn.getRhs()) and
583+
exists(DataFlow::PropWrite assgn, DataFlow::SourceNode obj |
584+
not exists(assgn.getPropertyName()) and
585+
not assgn.getWriteNode() instanceof Property and // not a write inside an object literal
586+
pred = assgn.getRhs() and
587+
assgn = obj.getAPropertyWrite() and
588588
succ = obj
589589
|
590590
obj instanceof DataFlow::ObjectLiteralNode
591591
or
592-
obj.getAPropertyRead("length").flowsToExpr(idx.getPropertyNameExpr())
592+
obj.getAPropertyRead("length").flowsToExpr(assgn.getPropertyNameExpr())
593593
)
594594
}
595595
}
@@ -614,8 +614,8 @@ module TaintTracking {
614614
override predicate stringManipulationStep(DataFlow::Node pred, DataFlow::Node target) {
615615
exists(DataFlow::ValueNode succ | target = succ |
616616
// string operations that propagate taint
617-
exists(string name | name = succ.getAstNode().(MethodCallExpr).getMethodName() |
618-
pred.asExpr() = succ.getAstNode().(MethodCallExpr).getReceiver() and
617+
exists(string name | name = succ.(DataFlow::MethodCallNode).getMethodName() |
618+
pred = succ.(DataFlow::MethodCallNode).getReceiver() and
619619
(
620620
// sorted, interesting, properties of String.prototype
621621
name =
@@ -634,7 +634,7 @@ module TaintTracking {
634634
name = "join"
635635
)
636636
or
637-
exists(int i | pred.asExpr() = succ.getAstNode().(MethodCallExpr).getArgument(i) |
637+
exists(int i | pred = succ.(DataFlow::MethodCallNode).getArgument(i) |
638638
name = "concat"
639639
or
640640
name = ["replace", "replaceAll"] and i = 1
@@ -649,10 +649,10 @@ module TaintTracking {
649649
)
650650
or
651651
// String.fromCharCode and String.fromCodePoint
652-
exists(int i, MethodCallExpr mce |
653-
mce = succ.getAstNode() and
654-
pred.asExpr() = mce.getArgument(i) and
655-
(mce.getMethodName() = "fromCharCode" or mce.getMethodName() = "fromCodePoint")
652+
exists(int i, DataFlow::MethodCallNode mcn |
653+
mcn = succ and
654+
pred = mcn.getArgument(i) and
655+
mcn.getMethodName() = ["fromCharCode", "fromCodePoint"]
656656
)
657657
or
658658
// `(encode|decode)URI(Component)?` propagate taint
@@ -778,11 +778,11 @@ module TaintTracking {
778778
* the parameters in `input`.
779779
*/
780780
predicate isUrlSearchParams(DataFlow::SourceNode params, DataFlow::Node input) {
781-
exists(DataFlow::GlobalVarRefNode urlSearchParams, NewExpr newUrlSearchParams |
781+
exists(DataFlow::GlobalVarRefNode urlSearchParams, DataFlow::NewNode newUrlSearchParams |
782782
urlSearchParams.getName() = "URLSearchParams" and
783-
newUrlSearchParams = urlSearchParams.getAnInstantiation().asExpr() and
784-
params.asExpr() = newUrlSearchParams and
785-
input.asExpr() = newUrlSearchParams.getArgument(0)
783+
newUrlSearchParams = urlSearchParams.getAnInstantiation() and
784+
params = newUrlSearchParams and
785+
input = newUrlSearchParams.getArgument(0)
786786
)
787787
}
788788

0 commit comments

Comments
 (0)