factor fetch import into NodeJSLib

This commit is contained in:
Erik Krogh Kristensen
2020-06-02 22:45:47 +02:00
parent 9c50acc0f9
commit 14f0d1687a
2 changed files with 15 additions and 11 deletions

View File

@@ -267,17 +267,7 @@ module ClientRequest {
DataFlow::Node url;
FetchUrlRequest() {
exists(string moduleName, DataFlow::SourceNode callee | this = callee.getACall() |
(
moduleName = "node-fetch" or
moduleName = "cross-fetch" or
moduleName = "isomorphic-fetch"
) and
callee = DataFlow::moduleImport(moduleName) and
url = getArgument(0)
)
or
this = DataFlow::globalVarRef("fetch").getACall() and
this = NodeJSLib::Fetch::moduleImport() and
url = getArgument(0)
}

View File

@@ -1134,4 +1134,18 @@ module NodeJSLib {
result = moduleImport().getAPropertyRead(member)
}
}
/**
* Provides predicates for working with the "node-fetch" module and its platform-specific instances as a single module.
*/
module Fetch {
/**
* Gets a node that imports the "node-fetch" module, or one of its platform-specific instances.
*/
DataFlow::SourceNode moduleImport() {
result = DataFlow::moduleImport(["node-fetch", "cross-fetch", "isomorphic-fetch"])
or
result = DataFlow::globalVarRef("fetch")
}
}
}