Merge pull request #8221 from erik-krogh/libProto

JS: recognize more module exports from the factory pattern
This commit is contained in:
Erik Krogh Kristensen
2022-04-29 11:23:53 +02:00
committed by GitHub
5 changed files with 36 additions and 5 deletions

View File

@@ -126,17 +126,23 @@ private DataFlow::Node getAValueExportedByPackage() {
// }));
// ```
// Such files are not recognized as modules, so we manually use `NodeModule::resolveMainModule` to resolve the file against a `package.json` file.
exists(ImmediatelyInvokedFunctionExpr func, DataFlow::ParameterNode prev, int i |
prev.getName() = "factory" and
func.getParameter(i) = prev.getParameter() and
result = func.getInvocation().getArgument(i).flow().getAFunctionValue().getAReturn() and
DataFlow::globalVarRef("define").getACall().getArgument(1) = prev.getALocalUse() and
exists(ImmediatelyInvokedFunctionExpr func, DataFlow::ParameterNode factory, int i |
factory.getName() = "factory" and
func.getParameter(i) = factory.getParameter() and
DataFlow::globalVarRef("define").getACall().getAnArgument() = factory.getALocalUse() and
func.getFile() =
min(int j, File f |
f = NodeModule::resolveMainModule(any(PackageJson pack | exists(pack.getPackageName())), j)
|
f order by j
)
|
result = func.getInvocation().getArgument(i).flow().getAFunctionValue().getAReturn()
or
exists(DataFlow::ParameterNode exports | exports.getName() = "exports" |
exports = func.getInvocation().getAnArgument().flow().getAFunctionValue().getParameter(0) and
result = exports.getAPropertyWrite().getRhs()
)
)
or
// the exported value is a call to a unique callee