1515import javascript
1616
1717private newtype TPortal =
18+ MkGlobalObjectPortal ( ) or
1819 MkNpmPackagePortal ( string pkgName ) {
1920 NpmPackagePortal:: imports ( _, pkgName ) or
2021 NpmPackagePortal:: imports ( _, pkgName , _) or
@@ -129,6 +130,22 @@ class Portal extends TPortal {
129130 abstract int depth ( ) ;
130131}
131132
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+
132149/**
133150 * A portal representing the exports value of the main module of an npm
134151 * package (that is, a value of `module.exports` for CommonJS modules, or
@@ -289,6 +306,11 @@ private module MemberPortal {
289306 base = MkNpmPackagePortal ( pkg ) and
290307 isRemote = false
291308 )
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
292314 }
293315
294316 /** Holds if the main module of `pkgName` exports `rhs` under the name `prop`. */
@@ -314,6 +336,14 @@ private module MemberPortal {
314336 base = MkNpmPackagePortal ( pkgName ) and
315337 escapes = true
316338 )
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
317347 }
318348}
319349
0 commit comments