Skip to content

Commit 14f0d16

Browse files
committed
factor fetch import into NodeJSLib
1 parent 9c50acc commit 14f0d16

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

javascript/ql/src/semmle/javascript/frameworks/ClientRequests.qll

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,7 @@ module ClientRequest {
267267
DataFlow::Node url;
268268

269269
FetchUrlRequest() {
270-
exists(string moduleName, DataFlow::SourceNode callee | this = callee.getACall() |
271-
(
272-
moduleName = "node-fetch" or
273-
moduleName = "cross-fetch" or
274-
moduleName = "isomorphic-fetch"
275-
) and
276-
callee = DataFlow::moduleImport(moduleName) and
277-
url = getArgument(0)
278-
)
279-
or
280-
this = DataFlow::globalVarRef("fetch").getACall() and
270+
this = NodeJSLib::Fetch::moduleImport() and
281271
url = getArgument(0)
282272
}
283273

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,4 +1134,18 @@ module NodeJSLib {
11341134
result = moduleImport().getAPropertyRead(member)
11351135
}
11361136
}
1137+
1138+
/**
1139+
* Provides predicates for working with the "node-fetch" module and its platform-specific instances as a single module.
1140+
*/
1141+
module Fetch {
1142+
/**
1143+
* Gets a node that imports the "node-fetch" module, or one of its platform-specific instances.
1144+
*/
1145+
DataFlow::SourceNode moduleImport() {
1146+
result = DataFlow::moduleImport(["node-fetch", "cross-fetch", "isomorphic-fetch"])
1147+
or
1148+
result = DataFlow::globalVarRef("fetch")
1149+
}
1150+
}
11371151
}

0 commit comments

Comments
 (0)