15
15
import javascript
16
16
17
17
private newtype TPortal =
18
+ MkGlobalObjectPortal ( ) or
18
19
MkNpmPackagePortal ( string pkgName ) {
19
20
NpmPackagePortal:: imports ( _, pkgName ) or
20
21
NpmPackagePortal:: imports ( _, pkgName , _) or
@@ -129,6 +130,22 @@ class Portal extends TPortal {
129
130
abstract int depth ( ) ;
130
131
}
131
132
133
+ /**
134
+ * A portal representing the global object.
135
+ */
136
+ private class GlobalObjectPortal extends Portal , MkGlobalObjectPortal {
137
+ override DataFlow:: SourceNode getAnExitNode ( boolean isRemote ) {
138
+ result = DataFlow:: globalObjectRef ( ) and
139
+ isRemote = true
140
+ }
141
+
142
+ override DataFlow:: Node getAnEntryNode ( boolean escapes ) { none ( ) }
143
+
144
+ override string toString ( ) { result = "(global)" }
145
+
146
+ override int depth ( ) { result = 1 }
147
+ }
148
+
132
149
/**
133
150
* A portal representing the exports value of the main module of an npm
134
151
* package (that is, a value of `module.exports` for CommonJS modules, or
@@ -289,6 +306,11 @@ private module MemberPortal {
289
306
base = MkNpmPackagePortal ( pkg ) and
290
307
isRemote = false
291
308
)
309
+ or
310
+ // global variable reads are a kind of property read
311
+ base instanceof GlobalObjectPortal and
312
+ read = DataFlow:: globalVarRef ( prop ) and
313
+ isRemote = true
292
314
}
293
315
294
316
/** Holds if the main module of `pkgName` exports `rhs` under the name `prop`. */
@@ -314,6 +336,14 @@ private module MemberPortal {
314
336
base = MkNpmPackagePortal ( pkgName ) and
315
337
escapes = true
316
338
)
339
+ or
340
+ // global variable writes are a kind of property write
341
+ base instanceof GlobalObjectPortal and
342
+ exists ( AssignExpr assgn |
343
+ assgn .getLhs ( ) = DataFlow:: globalVarRef ( prop ) .asExpr ( ) and
344
+ rhs = assgn .getRhs ( ) .flow ( )
345
+ ) and
346
+ escapes = true
317
347
}
318
348
}
319
349
0 commit comments