Skip to content

Commit 8a2c81b

Browse files
committed
JS: address review comments about duplicated logic
1 parent bbd60f5 commit 8a2c81b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/TaintedPath.qll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,19 @@ module TaintedPath {
6969
)
7070
or
7171
// string method calls of interest
72-
exists(DataFlow::MethodCallNode mcn | srclabel = dstlabel |
72+
exists(DataFlow::MethodCallNode mcn, string name |
73+
srclabel = dstlabel and dst = mcn and mcn.calls(src, name)
74+
|
7375
exists(string substringMethodName |
7476
substringMethodName = "substr" or
7577
substringMethodName = "substring" or
7678
substringMethodName = "slice"
7779
|
78-
mcn.calls(src, substringMethodName) and
80+
name = substringMethodName and
7981
// to avoid very dynamic transformations, require at least one fixed index
80-
exists(mcn.getAnArgument().asExpr().getIntValue()) and
81-
dst = mcn
82-
) or
82+
exists(mcn.getAnArgument().asExpr().getIntValue())
83+
)
84+
or
8385
exists(string argumentlessMethodName |
8486
argumentlessMethodName = "toLocaleLowerCase" or
8587
argumentlessMethodName = "toLocaleUpperCase" or
@@ -89,16 +91,14 @@ module TaintedPath {
8991
argumentlessMethodName = "trimLeft" or
9092
argumentlessMethodName = "trimRight"
9193
|
92-
mcn.calls(src, argumentlessMethodName) and
93-
dst = mcn
94+
name = argumentlessMethodName
9495
)
9596
or
96-
mcn.calls(src, "split") and
97-
dst = mcn and
98-
not exists (DataFlow::Node splitBy |
99-
splitBy = mcn.getArgument(0)|
97+
name = "split" and
98+
not exists(DataFlow::Node splitBy | splitBy = mcn.getArgument(0) |
10099
splitBy.mayHaveStringValue("/") or
101-
any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/").flowsTo(splitBy)
100+
any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/")
101+
.flowsTo(splitBy)
102102
)
103103
)
104104
}

0 commit comments

Comments
 (0)