Skip to content

Commit dfe3f25

Browse files
committed
JS: generalize to include default imports
1 parent d532815 commit dfe3f25

File tree

7 files changed

+13
-8
lines changed

7 files changed

+13
-8
lines changed

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module DataFlow {
3939
not exists(SsaExplicitDefinition ssa | p = ssa.getDef())
4040
} or
4141
TDestructuredModuleImportNode(ImportDeclaration decl) {
42-
decl.getASpecifier() instanceof NamedImportSpecifier
42+
exists(decl.getASpecifier().getImportedName())
4343
}
4444

4545
/**
@@ -346,10 +346,7 @@ module DataFlow {
346346
}
347347

348348
/**
349-
* A node referring to the module imported at a named ES2015 import declaration.
350-
*
351-
* Default imports and namespace imports do not fall into this category, as the
352-
* SSA definition of the local variable is used as the source of the module instead.
349+
* A node referring to the module imported at a named or default ES2015 import declaration.
353350
*/
354351
private class DestructuredModuleImportNode extends Node, TDestructuredModuleImportNode {
355352
ImportDeclaration imprt;
@@ -687,13 +684,14 @@ module DataFlow {
687684
/**
688685
* A named import specifier seen as a property read on the imported module.
689686
*/
690-
private class NamedImportSpecifierAsPropRead extends PropRead {
687+
private class ImportSpecifierAsPropRead extends PropRead {
691688
ImportDeclaration imprt;
692689

693-
NamedImportSpecifier spec;
690+
ImportSpecifier spec;
694691

695-
NamedImportSpecifierAsPropRead() {
692+
ImportSpecifierAsPropRead() {
696693
spec = imprt.getASpecifier() and
694+
exists(spec.getImportedName()) and
697695
exists(SsaExplicitDefinition ssa |
698696
ssa.getDef() = spec and
699697
this = TSsaDefNode(ssa)

javascript/ql/test/library-tests/InterProceduralFlow/TaintTracking.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| global.js:5:22:5:35 | "also tainted" | global.js:9:13:9:22 | g(source1) |
1919
| global.js:5:22:5:35 | "also tainted" | global.js:10:13:10:22 | g(source2) |
2020
| nodeJsLib.js:1:15:1:23 | "tainted" | esClient.js:7:13:7:18 | nj.foo |
21+
| nodeJsLib.js:1:15:1:23 | "tainted" | esClient.js:10:13:10:17 | njFoo |
2122
| nodeJsLib.js:1:15:1:23 | "tainted" | nodeJsClient.js:4:13:4:18 | nj.foo |
2223
| nodeJsLib.js:2:15:2:23 | "tainted" | esClient.js:7:13:7:18 | nj.foo |
2324
| nodeJsLib.js:2:15:2:23 | "tainted" | esClient.js:10:13:10:17 | njFoo |

javascript/ql/test/library-tests/ModuleImportNodes/ModuleImportNode_getAPropertyRead.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| amd2.js:2:12:2:24 | require('fs') | amd2.js:3:3:3:17 | fs.readFileSync |
33
| destructuringES6.js:1:1:1:41 | import ... ctron'; | destructuringES6.js:1:10:1:22 | BrowserWindow |
44
| destructuringRequire.js:1:27:1:45 | require('electron') | destructuringRequire.js:1:9:1:21 | BrowserWindow |
5+
| instanceThroughDefaultImport.js:1:1:1:82 | import ... tance'; | instanceThroughDefaultImport.js:1:8:1:42 | myDefaultImportedModuleInstanceName |
56
| moduleUses.js:1:11:1:24 | require('mod') | moduleUses.js:3:1:3:16 | mod.moduleMethod |
67
| moduleUses.js:1:11:1:24 | require('mod') | moduleUses.js:5:9:5:26 | mod.moduleFunction |
78
| moduleUses.js:1:11:1:24 | require('mod') | moduleUses.js:8:9:8:31 | mod.con ... unction |

javascript/ql/test/library-tests/ModuleImportNodes/ModuleImportNode_getPath.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| amd2.js:2:12:2:24 | require('fs') | fs |
33
| destructuringES6.js:1:1:1:41 | import ... ctron'; | electron |
44
| destructuringRequire.js:1:27:1:45 | require('electron') | electron |
5+
| instanceThroughDefaultImport.js:1:1:1:82 | import ... tance'; | myDefaultImportedModuleInstance |
56
| instanceThroughDefaultImport.js:1:8:1:42 | myDefaultImportedModuleInstanceName | myDefaultImportedModuleInstance |
67
| instanceThroughNamespaceImport.js:1:8:1:49 | myNamespaceImportedModuleInstanceName | myNamespaceImportedModuleInstance |
78
| instanceThroughRequire.js:1:36:1:70 | require ... tance') | myRequiredModuleInstance |

javascript/ql/test/library-tests/ModuleImportNodes/moduleImport.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| fs | amd1.js:1:25:1:26 | fs |
44
| fs | amd2.js:2:12:2:24 | require('fs') |
55
| mod | moduleUses.js:1:11:1:24 | require('mod') |
6+
| myDefaultImportedModuleInstance | instanceThroughDefaultImport.js:1:1:1:82 | import ... tance'; |
67
| myDefaultImportedModuleInstance | instanceThroughDefaultImport.js:1:8:1:42 | myDefaultImportedModuleInstanceName |
78
| myNamespaceImportedModuleInstance | instanceThroughNamespaceImport.js:1:8:1:49 | myNamespaceImportedModuleInstanceName |
89
| myRequiredModuleInstance | instanceThroughRequire.js:1:36:1:70 | require ... tance') |

javascript/ql/test/library-tests/ModuleImportNodes/moduleImportProp.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
| mod | moduleField | moduleUses.js:11:1:11:15 | mod.moduleField |
77
| mod | moduleFunction | moduleUses.js:5:9:5:26 | mod.moduleFunction |
88
| mod | moduleMethod | moduleUses.js:3:1:3:16 | mod.moduleMethod |
9+
| myDefaultImportedModuleInstance | default | instanceThroughDefaultImport.js:1:8:1:42 | myDefaultImportedModuleInstanceName |

javascript/ql/test/library-tests/Portals/PortalExit.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,4 +1038,6 @@
10381038
| (return (root https://www.npmjs.com/package/m2)) | src/m3/tst3.js:4:1:4:11 | new A("me") | false |
10391039
| (return (root https://www.npmjs.com/package/m2)) | src/m3/tst3.js:5:1:5:11 | new A("me") | false |
10401040
| (root https://www.npmjs.com/package/m1) | src/m3/index.js:1:10:1:22 | require("m1") | false |
1041+
| (root https://www.npmjs.com/package/m2) | src/m3/tst2.js:1:1:1:25 | import ... m "m2"; | false |
1042+
| (root https://www.npmjs.com/package/m2) | src/m3/tst3.js:1:1:1:19 | import A from "m2"; | false |
10411043
| (root https://www.npmjs.com/package/m2) | src/m3/tst3.js:1:8:1:8 | A | false |

0 commit comments

Comments
 (0)