Skip to content

Commit 09aca6b

Browse files
authored
Merge pull request #17212 from mbaluda/main
Add support for importing NPM modules in XSJS sources
2 parents d97a301 + be0a60a commit 09aca6b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

javascript/ql/lib/semmle/javascript/NodeJS.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ private predicate isRequire(DataFlow::Node nd) {
295295
isCreateRequire(call.getCallee().flow()) and
296296
nd = call.flow()
297297
)
298+
or
299+
// `$.require('underscore');`.
300+
// NPM as supported in [XSJS files](https://www.npmjs.com/package/@sap/async-xsjs#npm-packages-support).
301+
exists(MethodCallExpr require |
302+
nd.getFile().getExtension() = ["xsjs", "xsjslib"] and
303+
require.getCalleeName() = "require" and
304+
require.getReceiver().(GlobalVarAccess).getName() = "$" and
305+
nd = require.getCallee().flow()
306+
)
298307
}
299308

300309
/**

javascript/ql/test/query-tests/Security/CWE-326/InsufficientKeySize.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
| tst.js:35:13:35:43 | crypto. ... an(512) | Creation of an asymmetric key uses 512 bits, which is below 2048 and considered breakable. |
1010
| tst.js:39:13:39:33 | new Nod ... : 512}) | Creation of an asymmetric RSA key uses 512 bits, which is below 2048 and considered breakable. |
1111
| tst.js:43:1:43:31 | key.gen ... 65537) | Creation of an asymmetric RSA key uses 512 bits, which is below 2048 and considered breakable. |
12+
| tst.xsjs:3:14:3:71 | crypto. ... 1024 }) | Creation of an asymmetric RSA key uses 1024 bits, which is below 2048 and considered breakable. |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const crypto = $.require("crypto");
2+
3+
const bad1 = crypto.generateKeyPairSync("rsa", { modulusLength: 1024 }); // NOT OK
4+
5+
const good1 = crypto.generateKeyPairSync("rsa", { modulusLength: 4096 }); // OK

0 commit comments

Comments
 (0)