Skip to content

Commit bfe88e9

Browse files
committed
JS: make Closure::moduleImport handle member access.
1 parent 0558b58 commit bfe88e9

File tree

7 files changed

+80
-46
lines changed

7 files changed

+80
-46
lines changed

javascript/ql/src/semmle/javascript/Closure.qll

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ module Closure {
170170
isLibraryNamespacePath(result) and
171171
node = DataFlow::globalVarRef(result)
172172
or
173-
isLibraryNamespacePath(result) and
174-
exists(DataFlow::PropRead read | node = read |
175-
result = getLibraryAccessPath(read.getBase().getALocalSource()) + "." + read.getPropertyName()
173+
exists(DataFlow::SourceNode base, string basePath, string prop |
174+
basePath = getLibraryAccessPath(base) and
175+
isLibraryNamespacePath(basePath) and
176+
node = base.getAPropertyRead(prop) and
177+
result = basePath + "." + prop
176178
)
177179
or
178180
// Associate an access path with the immediate RHS of a store on a closure namespace.
@@ -194,16 +196,9 @@ module Closure {
194196
}
195197

196198
/**
197-
* Gets a dataflow node that refers to the given Closure module.
199+
* Gets a dataflow node that refers to the given value exported from a Closure module.
198200
*/
199201
DataFlow::SourceNode moduleImport(string moduleName) {
200202
getLibraryAccessPath(result) = moduleName
201203
}
202-
203-
/**
204-
* Gets a dataflow node that refers to the given member of a Closure module.
205-
*/
206-
DataFlow::SourceNode moduleMember(string moduleName, string memberName) {
207-
result = moduleImport(moduleName).getAPropertyRead(memberName)
208-
}
209204
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| tests/uri.js:5:5:5:11 | net.Uri |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import javascript
2+
3+
select Closure::moduleImport("goog.net.Uri")

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1+
| goog | tests/es6Module.js:1:1:1:4 | goog |
2+
| goog | tests/es6ModuleDefault.js:1:1:1:4 | goog |
3+
| goog | tests/globalModule.js:1:1:1:4 | goog |
4+
| goog | tests/globalModuleDefault.js:1:1:1:4 | goog |
5+
| goog | tests/googModule.js:1:1:1:4 | goog |
6+
| goog | tests/googModuleDefault.js:1:1:1:4 | goog |
7+
| goog | tests/requireFromEs6.js:3:20:3:23 | goog |
8+
| goog | tests/requireFromEs6.js:4:27:4:30 | goog |
9+
| goog | tests/requireFromEs6.js:6:17:6:20 | goog |
10+
| goog | tests/requireFromEs6.js:7:24:7:27 | goog |
11+
| goog | tests/requireFromEs6.js:9:18:9:21 | goog |
12+
| goog | tests/requireFromEs6.js:10:25:10:28 | goog |
13+
| goog | tests/requireFromGlobalModule.js:1:1:1:4 | goog |
14+
| goog | tests/requireFromGlobalModule.js:2:1:2:4 | goog |
15+
| goog | tests/requireFromGlobalModule.js:4:1:4:4 | goog |
16+
| goog | tests/requireFromGlobalModule.js:5:1:5:4 | goog |
17+
| goog | tests/requireFromGlobalModule.js:7:1:7:4 | goog |
18+
| goog | tests/requireFromGlobalModule.js:8:1:8:4 | goog |
19+
| goog | tests/requireFromGoogModule.js:1:1:1:4 | goog |
20+
| goog | tests/requireFromGoogModule.js:3:20:3:23 | goog |
21+
| goog | tests/requireFromGoogModule.js:4:27:4:30 | goog |
22+
| goog | tests/requireFromGoogModule.js:6:17:6:20 | goog |
23+
| goog | tests/requireFromGoogModule.js:7:24:7:27 | goog |
24+
| goog | tests/requireFromGoogModule.js:9:18:9:21 | goog |
25+
| goog | tests/requireFromGoogModule.js:10:25:10:28 | goog |
26+
| goog | tests/uri.js:1:1:1:4 | goog |
27+
| goog | tests/uri.js:3:11:3:14 | goog |
28+
| goog.declareModuleId | tests/es6Module.js:1:1:1:20 | goog.declareModuleId |
29+
| goog.declareModuleId | tests/es6ModuleDefault.js:1:1:1:20 | goog.declareModuleId |
30+
| goog.module | tests/googModule.js:1:1:1:11 | goog.module |
31+
| goog.module | tests/googModuleDefault.js:1:1:1:11 | goog.module |
32+
| goog.module | tests/requireFromGoogModule.js:1:1:1:11 | goog.module |
33+
| goog.module | tests/uri.js:1:1:1:11 | goog.module |
34+
| goog.net | tests/uri.js:3:11:3:34 | goog.re ... g.net') |
35+
| goog.net.Uri | tests/uri.js:5:5:5:11 | net.Uri |
36+
| goog.provide | tests/globalModule.js:1:1:1:12 | goog.provide |
37+
| goog.provide | tests/globalModuleDefault.js:1:1:1:12 | goog.provide |
38+
| goog.require | tests/requireFromEs6.js:3:20:3:31 | goog.require |
39+
| goog.require | tests/requireFromEs6.js:4:27:4:38 | goog.require |
40+
| goog.require | tests/requireFromEs6.js:6:17:6:28 | goog.require |
41+
| goog.require | tests/requireFromEs6.js:7:24:7:35 | goog.require |
42+
| goog.require | tests/requireFromEs6.js:9:18:9:29 | goog.require |
43+
| goog.require | tests/requireFromEs6.js:10:25:10:36 | goog.require |
44+
| goog.require | tests/requireFromGlobalModule.js:1:1:1:12 | goog.require |
45+
| goog.require | tests/requireFromGlobalModule.js:2:1:2:12 | goog.require |
46+
| goog.require | tests/requireFromGlobalModule.js:4:1:4:12 | goog.require |
47+
| goog.require | tests/requireFromGlobalModule.js:5:1:5:12 | goog.require |
48+
| goog.require | tests/requireFromGlobalModule.js:7:1:7:12 | goog.require |
49+
| goog.require | tests/requireFromGlobalModule.js:8:1:8:12 | goog.require |
50+
| goog.require | tests/requireFromGoogModule.js:3:20:3:31 | goog.require |
51+
| goog.require | tests/requireFromGoogModule.js:4:27:4:38 | goog.require |
52+
| goog.require | tests/requireFromGoogModule.js:6:17:6:28 | goog.require |
53+
| goog.require | tests/requireFromGoogModule.js:7:24:7:35 | goog.require |
54+
| goog.require | tests/requireFromGoogModule.js:9:18:9:29 | goog.require |
55+
| goog.require | tests/requireFromGoogModule.js:10:25:10:36 | goog.require |
56+
| goog.require | tests/uri.js:3:11:3:22 | goog.require |
157
| x | tests/globalModule.js:3:1:3:1 | x |
258
| x | tests/globalModuleDefault.js:3:1:3:1 | x |
359
| x | tests/requireFromGlobalModule.js:10:1:10:1 | x |
@@ -26,6 +82,9 @@
2682
| x.y.z.es6 | tests/requireFromGlobalModule.js:7:1:7:25 | goog.re ... z.es6') |
2783
| x.y.z.es6 | tests/requireFromGlobalModule.js:16:1:16:9 | x.y.z.es6 |
2884
| x.y.z.es6 | tests/requireFromGoogModule.js:6:17:6:41 | goog.re ... z.es6') |
85+
| x.y.z.es6.fun | tests/requireFromEs6.js:15:1:15:13 | es6Module.fun |
86+
| x.y.z.es6.fun | tests/requireFromGlobalModule.js:16:1:16:13 | x.y.z.es6.fun |
87+
| x.y.z.es6.fun | tests/requireFromGoogModule.js:15:1:15:13 | es6Module.fun |
2988
| x.y.z.es6default | tests/requireFromEs6.js:7:24:7:55 | goog.re ... fault') |
3089
| x.y.z.es6default | tests/requireFromGlobalModule.js:8:1:8:32 | goog.re ... fault') |
3190
| x.y.z.es6default | tests/requireFromGlobalModule.js:17:1:17:16 | x.y.z.es6default |
@@ -36,6 +95,9 @@
3695
| x.y.z.global | tests/requireFromGlobalModule.js:10:1:10:12 | x.y.z.global |
3796
| x.y.z.global | tests/requireFromGoogModule.js:3:20:3:47 | goog.re ... lobal') |
3897
| x.y.z.global.fun | tests/globalModule.js:4:6:4:10 | () {} |
98+
| x.y.z.global.fun | tests/requireFromEs6.js:12:1:12:16 | globalModule.fun |
99+
| x.y.z.global.fun | tests/requireFromGlobalModule.js:10:1:10:16 | x.y.z.global.fun |
100+
| x.y.z.global.fun | tests/requireFromGoogModule.js:12:1:12:16 | globalModule.fun |
39101
| x.y.z.globaldefault | tests/globalModuleDefault.js:3:23:3:39 | function fun() {} |
40102
| x.y.z.globaldefault | tests/requireFromEs6.js:4:27:4:61 | goog.re ... fault') |
41103
| x.y.z.globaldefault | tests/requireFromGlobalModule.js:2:1:2:35 | goog.re ... fault') |
@@ -45,6 +107,9 @@
45107
| x.y.z.goog | tests/requireFromGlobalModule.js:4:1:4:26 | goog.re ... .goog') |
46108
| x.y.z.goog | tests/requireFromGlobalModule.js:13:1:13:10 | x.y.z.goog |
47109
| x.y.z.goog | tests/requireFromGoogModule.js:9:18:9:43 | goog.re ... .goog') |
110+
| x.y.z.goog.fun | tests/requireFromEs6.js:18:1:18:14 | googModule.fun |
111+
| x.y.z.goog.fun | tests/requireFromGlobalModule.js:13:1:13:14 | x.y.z.goog.fun |
112+
| x.y.z.goog.fun | tests/requireFromGoogModule.js:18:1:18:14 | googModule.fun |
48113
| x.y.z.googdefault | tests/requireFromEs6.js:10:25:10:57 | goog.re ... fault') |
49114
| x.y.z.googdefault | tests/requireFromGlobalModule.js:5:1:5:33 | goog.re ... fault') |
50115
| x.y.z.googdefault | tests/requireFromGlobalModule.js:14:1:14:17 | x.y.z.googdefault |

javascript/ql/test/library-tests/Closure/moduleMember.expected

Lines changed: 0 additions & 31 deletions
This file was deleted.

javascript/ql/test/library-tests/Closure/moduleMember.ql

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
goog.module('uritest');
2+
3+
let net = goog.require('goog.net');
4+
5+
new net.Uri();

0 commit comments

Comments
 (0)