add a few arrary methods to TaintedPath.qll

This commit is contained in:
Erik Krogh Kristensen
2020-02-11 11:19:57 +01:00
parent b9bc21637e
commit 35d8151374
2 changed files with 36 additions and 5 deletions

View File

@@ -93,13 +93,38 @@ module TaintedPath {
| |
name = argumentlessMethodName name = argumentlessMethodName
) )
)
or or
// array method calls of interest
exists(DataFlow::MethodCallNode mcn, string name | dst = mcn and mcn.calls(src, name) |
// A `str.split()` call can either split into path elements (`str.split("/")`) or split by some other string.
name = "split" and name = "split" and
not exists(DataFlow::Node splitBy | splitBy = mcn.getArgument(0) | (
if
exists(DataFlow::Node splitBy | splitBy = mcn.getArgument(0) |
splitBy.mayHaveStringValue("/") or splitBy.mayHaveStringValue("/") or
any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/") any(DataFlow::RegExpLiteralNode reg | reg.getRoot().getAMatchedString() = "/")
.flowsTo(splitBy) .flowsTo(splitBy)
) )
then
srclabel.(Label::PosixPath).canContainDotDotSlash() and
dstlabel instanceof Label::SplitPath
else srclabel = dstlabel
)
or
(
name = "pop" or
name = "shift" or
name = "slice" or
name = "splice"
) and
dstlabel instanceof Label::SplitPath and
srclabel instanceof Label::SplitPath
or
name = "join" and
mcn.getArgument(0).mayHaveStringValue("/") and
srclabel instanceof Label::SplitPath and
dstlabel.(Label::PosixPath).canContainDotDotSlash()
) )
} }

View File

@@ -108,6 +108,12 @@ module TaintedPath {
not (isNormalized() and isAbsolute()) not (isNormalized() and isAbsolute())
} }
} }
class SplitPath extends DataFlow::FlowLabel {
SplitPath() {
this = "splitPath"
}
}
} }
/** /**