Skip to content

Commit 35d8151

Browse files
committed
add a few arrary methods to TaintedPath.qll
1 parent b9bc216 commit 35d8151

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,38 @@ module TaintedPath {
9393
|
9494
name = argumentlessMethodName
9595
)
96-
or
96+
)
97+
or
98+
// array method calls of interest
99+
exists(DataFlow::MethodCallNode mcn, string name | dst = mcn and mcn.calls(src, name) |
100+
// A `str.split()` call can either split into path elements (`str.split("/")`) or split by some other string.
97101
name = "split" and
98-
not exists(DataFlow::Node splitBy | splitBy = mcn.getArgument(0) |
99-
splitBy.mayHaveStringValue("/") or
100-
any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/")
101-
.flowsTo(splitBy)
102+
(
103+
if
104+
exists(DataFlow::Node splitBy | splitBy = mcn.getArgument(0) |
105+
splitBy.mayHaveStringValue("/") or
106+
any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/")
107+
.flowsTo(splitBy)
108+
)
109+
then
110+
srclabel.(Label::PosixPath).canContainDotDotSlash() and
111+
dstlabel instanceof Label::SplitPath
112+
else srclabel = dstlabel
102113
)
114+
or
115+
(
116+
name = "pop" or
117+
name = "shift" or
118+
name = "slice" or
119+
name = "splice"
120+
) and
121+
dstlabel instanceof Label::SplitPath and
122+
srclabel instanceof Label::SplitPath
123+
or
124+
name = "join" and
125+
mcn.getArgument(0).mayHaveStringValue("/") and
126+
srclabel instanceof Label::SplitPath and
127+
dstlabel.(Label::PosixPath).canContainDotDotSlash()
103128
)
104129
}
105130

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ module TaintedPath {
108108
not (isNormalized() and isAbsolute())
109109
}
110110
}
111+
112+
class SplitPath extends DataFlow::FlowLabel {
113+
SplitPath() {
114+
this = "splitPath"
115+
}
116+
}
111117
}
112118

113119
/**

0 commit comments

Comments
 (0)