Skip to content

Commit 5d232bb

Browse files
committed
recognize more src folders when "main" in package.json points to a compiled output
1 parent eda7616 commit 5d232bb

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

javascript/ql/src/semmle/javascript/NodeModuleResolutionImpl.qll

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ File resolveMainModule(PackageJSON pkg, int priority) {
102102
)
103103
)
104104
or
105-
exists(Folder folder | folder = pkg.getFile().getParentContainer() |
106-
result =
107-
tryExtensions([folder, folder.getChildContainer(["src", "lib"])], "index",
108-
priority - prioritiesPerCandidate())
105+
exists(Folder folder, Folder child |
106+
child = folder or
107+
child = folder.getChildContainer(getASrcFolderName()) or
108+
child =
109+
folder.getChildContainer(getASrcFolderName()).(Folder).getChildContainer(getASrcFolderName())
110+
|
111+
folder = pkg.getFile().getParentContainer() and
112+
result = tryExtensions(child, "index", priority - prioritiesPerCandidate())
109113
)
110114
or
111115
// if there is no main module, then we look for files that are explicitly included in the published package.
@@ -130,6 +134,11 @@ File resolveMainModule(PackageJSON pkg, int priority) {
130134
)
131135
}
132136

137+
/**
138+
* Gets a folder name that is a common source folder name.
139+
*/
140+
private string getASrcFolderName() { result = ["ts", "js", "src", "lib"] }
141+
133142
/**
134143
* A JSON string in a `package.json` file specifying the path of the main
135144
* module of the package.

javascript/ql/test/query-tests/Performance/ReDoS/PolynomialBackTracking.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
| lib/closure.js:4:6:4:7 | u* | Strings with many repetitions of 'u' can start matching anywhere after the start of the preceeding u*o |
3131
| lib/lib.js:1:15:1:16 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3232
| lib/lib.js:8:3:8:4 | f* | Strings with many repetitions of 'f' can start matching anywhere after the start of the preceeding f*g |
33+
| lib/otherLib/js/src/index.js:2:3:2:4 | a* | Strings with many repetitions of 'a' can start matching anywhere after the start of the preceeding a*b |
3334
| 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 |
3435
| polynomial-redos.js:7:24:7:26 | \\s+ | Strings with many repetitions of ' ' can start matching anywhere after the start of the preceeding \\s+$ |
3536
| polynomial-redos.js:8:17:8:18 | * | Strings with many repetitions of ' ' can start matching anywhere after the start of the preceeding *, * |

javascript/ql/test/query-tests/Performance/ReDoS/PolynomialReDoS.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ nodes
1111
| lib/lib.js:7:19:7:22 | name |
1212
| lib/lib.js:8:13:8:16 | name |
1313
| lib/lib.js:8:13:8:16 | name |
14+
| lib/otherLib/js/src/index.js:1:28:1:31 | name |
15+
| lib/otherLib/js/src/index.js:1:28:1:31 | name |
16+
| lib/otherLib/js/src/index.js:2:13:2:16 | name |
17+
| lib/otherLib/js/src/index.js:2:13:2:16 | name |
1418
| lib/sublib/factory.js:12:26:12:29 | name |
1519
| lib/sublib/factory.js:12:26:12:29 | name |
1620
| lib/sublib/factory.js:13:24:13:27 | name |
@@ -170,6 +174,10 @@ edges
170174
| lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name |
171175
| lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name |
172176
| lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name |
177+
| lib/otherLib/js/src/index.js:1:28:1:31 | name | lib/otherLib/js/src/index.js:2:13:2:16 | name |
178+
| lib/otherLib/js/src/index.js:1:28:1:31 | name | lib/otherLib/js/src/index.js:2:13:2:16 | name |
179+
| lib/otherLib/js/src/index.js:1:28:1:31 | name | lib/otherLib/js/src/index.js:2:13:2:16 | name |
180+
| lib/otherLib/js/src/index.js:1:28:1:31 | name | lib/otherLib/js/src/index.js:2:13:2:16 | name |
173181
| lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name |
174182
| lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name |
175183
| lib/sublib/factory.js:12:26:12:29 | name | lib/sublib/factory.js:13:24:13:27 | name |
@@ -315,6 +323,7 @@ edges
315323
| lib/closure.js:4:5:4:17 | /u*o/.test(x) | lib/closure.js:3:21:3:21 | x | lib/closure.js:4:16:4:16 | x | This $@ that depends on $@ may run slow on strings with many repetitions of 'u'. | lib/closure.js:4:6:4:7 | u* | regular expression | lib/closure.js:3:21:3:21 | x | library input |
316324
| lib/lib.js:4:2:4:18 | regexp.test(name) | lib/lib.js:3:28:3:31 | name | lib/lib.js:4:14:4:17 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'a'. | lib/lib.js:1:15:1:16 | a* | regular expression | lib/lib.js:3:28:3:31 | name | library input |
317325
| lib/lib.js:8:2:8:17 | /f*g/.test(name) | lib/lib.js:7:19:7:22 | name | lib/lib.js:8:13:8:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'f'. | lib/lib.js:8:3:8:4 | f* | regular expression | lib/lib.js:7:19:7:22 | name | library input |
326+
| lib/otherLib/js/src/index.js:2:2:2:17 | /a*b/.test(name) | lib/otherLib/js/src/index.js:1:28:1:31 | name | lib/otherLib/js/src/index.js:2:13:2:16 | name | This $@ that depends on $@ may run slow on strings with many repetitions of 'a'. | lib/otherLib/js/src/index.js:2:3:2:4 | a* | regular expression | lib/otherLib/js/src/index.js:1:28:1:31 | name | library input |
318327
| 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 |
319328
| 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 |
320329
| 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 |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function (name) {
2+
/a*b/.test(name); // NOT OK
3+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "my-other-lib",
3+
"version": "0.0.7",
4+
"main": "./js/src/index.js",
5+
"scripts": {
6+
"build": "tsc"
7+
}
8+
}

0 commit comments

Comments
 (0)