mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +01:00
Merge pull request #8221 from erik-krogh/libProto
JS: recognize more module exports from the factory pattern
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
| lib/snapdragon.js:7:28:7:29 | a* | Strings starting with 'a' and with many repetitions of 'a' can start matching anywhere after the start of the preceeding aa*$ |
|
||||
| lib/snapdragon.js:15:26:15:27 | a* | Strings starting with 'a' and with many repetitions of 'a' can start matching anywhere after the start of the preceeding aa*$ |
|
||||
| lib/snapdragon.js:23:22:23:23 | a* | Strings starting with 'a' and with many repetitions of 'a' can start matching anywhere after the start of the preceeding aa*$ |
|
||||
| lib/subLib4/factory.js:8:3:8:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
|
||||
| lib/sublib/factory.js:13:14:13:15 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
|
||||
| polynomial-redos.js:7:24:7:26 | \\s+ | Strings with many repetitions of ' ' can start matching anywhere after the start of the preceeding \\s+$ |
|
||||
| polynomial-redos.js:8:17:8:18 | * | Strings with many repetitions of ' ' can start matching anywhere after the start of the preceeding *, * |
|
||||
|
||||
@@ -47,6 +47,10 @@ nodes
|
||||
| lib/snapdragon.js:23:5:23:12 | node.val |
|
||||
| lib/snapdragon.js:23:5:23:12 | node.val |
|
||||
| lib/snapdragon.js:25:22:25:26 | input |
|
||||
| lib/subLib4/factory.js:7:27:7:30 | name |
|
||||
| lib/subLib4/factory.js:7:27:7:30 | name |
|
||||
| lib/subLib4/factory.js:8:13:8:16 | name |
|
||||
| lib/subLib4/factory.js:8:13:8:16 | name |
|
||||
| lib/sublib/factory.js:12:26:12:29 | name |
|
||||
| lib/sublib/factory.js:12:26:12:29 | name |
|
||||
| lib/sublib/factory.js:13:24:13:27 | name |
|
||||
@@ -238,6 +242,10 @@ edges
|
||||
| lib/snapdragon.js:23:5:23:8 | node | lib/snapdragon.js:23:5:23:12 | node.val |
|
||||
| lib/snapdragon.js:23:5:23:8 | node | lib/snapdragon.js:23:5:23:12 | node.val |
|
||||
| lib/snapdragon.js:25:22:25:26 | input | lib/snapdragon.js:22:44:22:47 | node |
|
||||
| lib/subLib4/factory.js:7:27:7:30 | name | lib/subLib4/factory.js:8:13:8:16 | name |
|
||||
| lib/subLib4/factory.js:7:27:7:30 | name | lib/subLib4/factory.js:8:13:8:16 | name |
|
||||
| lib/subLib4/factory.js:7:27:7:30 | name | lib/subLib4/factory.js:8:13:8:16 | name |
|
||||
| lib/subLib4/factory.js:7:27:7:30 | name | lib/subLib4/factory.js:8:13:8:16 | name |
|
||||
| lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name |
|
||||
| lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name |
|
||||
| lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name |
|
||||
@@ -389,6 +397,7 @@ edges
|
||||
| lib/snapdragon.js:7:15:7:32 | this.match(/aa*$/) | lib/snapdragon.js:3:34:3:38 | input | lib/snapdragon.js:7:15:7:18 | this | This $@ that depends on $@ may run slow on strings starting with 'a' and with many repetitions of 'a'. | lib/snapdragon.js:7:28:7:29 | a* | regular expression | lib/snapdragon.js:3:34:3:38 | input | library input |
|
||||
| lib/snapdragon.js:15:13:15:30 | this.match(/aa*$/) | lib/snapdragon.js:12:34:12:38 | input | lib/snapdragon.js:15:13:15:16 | this | This $@ that depends on $@ may run slow on strings starting with 'a' and with many repetitions of 'a'. | lib/snapdragon.js:15:26:15:27 | a* | regular expression | lib/snapdragon.js:12:34:12:38 | input | library input |
|
||||
| lib/snapdragon.js:23:5:23:26 | node.va ... /aa*$/) | lib/snapdragon.js:20:34:20:38 | input | lib/snapdragon.js:23:5:23:12 | node.val | This $@ that depends on $@ may run slow on strings starting with 'a' and with many repetitions of 'a'. | lib/snapdragon.js:23:22:23:23 | a* | regular expression | lib/snapdragon.js:20:34:20:38 | input | library input |
|
||||
| lib/subLib4/factory.js:8:2:8:17 | /f*g/.test(name) | lib/subLib4/factory.js:7:27:7:30 | name | lib/subLib4/factory.js:8:13:8:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/subLib4/factory.js:8:3:8:4 | f* | regular expression | lib/subLib4/factory.js:7:27:7:30 | name | library input |
|
||||
| lib/sublib/factory.js:13:13:13:28 | /f*g/.test(name) | lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/sublib/factory.js:13:14:13:15 | f* | regular expression | lib/sublib/factory.js:12:26:12:29 | name | library input |
|
||||
| polynomial-redos.js:7:2:7:34 | tainted ... /g, '') | polynomial-redos.js:5:16:5:32 | req.query.tainted | polynomial-redos.js:7:2:7:8 | tainted | This $@ that depends on $@ may run slow on strings with many repetitions of ' '. | polynomial-redos.js:7:24:7:26 | \\s+ | regular expression | polynomial-redos.js:5:16:5:32 | req.query.tainted | a user-provided value |
|
||||
| polynomial-redos.js:8:2:8:23 | tainted ... *, */) | polynomial-redos.js:5:16:5:32 | req.query.tainted | polynomial-redos.js:8:2:8:8 | tainted | This $@ that depends on $@ may run slow on strings with many repetitions of ' '. | polynomial-redos.js:8:17:8:18 | * | regular expression | polynomial-redos.js:5:16:5:32 | req.query.tainted | a user-provided value |
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define('some-lib', ['exports'], factory) :
|
||||
(global = global || self, factory(global.JSData = {}));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
|
||||
exports.foo = function (name) {
|
||||
/f*g/.test(name); // NOT OK
|
||||
}
|
||||
})));
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "my-sub-lib",
|
||||
"version": "0.0.7",
|
||||
"main": "./factory.js"
|
||||
}
|
||||
Reference in New Issue
Block a user