Skip to content

Commit 0896be0

Browse files
authored
Merge pull request #20844 from Eliav2/20823-globalVarRef-document-defaultView
javascript: Add support for `document.defaultView` in global variable references
2 parents 7db06ca + 69ba764 commit 0896be0

File tree

6 files changed

+17
-0
lines changed

6 files changed

+17
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
5+
- JavaScript `DataFlow::globalVarRef` now recognizes `document.defaultView` as an alias of `window`, allowing flows such as `document.defaultView.history.pushState(...)` to be modeled and found by queries relying on `globalVarRef("history")`.

javascript/ql/lib/semmle/javascript/dataflow/Nodes.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ DataFlow::SourceNode globalObjectRef() {
393393
// DOM
394394
result = globalVariable("window")
395395
or
396+
// DOM alias via `document.defaultView`
397+
result = globalVariable("document").getAPropertyRead("defaultView")
398+
or
396399
// Node.js
397400
result = globalVariable("global")
398401
or

javascript/ql/test/library-tests/Nodes/globalObjectRef.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
| tst2.js:8:1:8:6 | global |
66
| tst3.js:1:1:1:0 | this |
77
| tst3.js:3:9:3:19 | goog.global |
8+
| tst4.js:1:1:1:0 | this |
9+
| tst4.js:1:1:1:38 | require ... ultView |
810
| tst.js:1:1:1:0 | this |
911
| tst.js:1:1:1:6 | window |
1012
| tst.js:3:1:3:6 | window |
1113
| tst.js:4:1:4:6 | window |
1214
| tst.js:5:1:5:4 | self |
1315
| tst.js:6:1:6:10 | globalThis |
16+
| tst.js:7:1:7:20 | document.defaultView |

javascript/ql/test/library-tests/Nodes/globalVarRef.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
| Object | tst2.js:8:1:8:13 | global.Object |
22
| String | tst2.js:9:1:9:11 | this.String |
33
| document | tst2.js:2:1:2:26 | require ... ument") |
4+
| document | tst4.js:1:1:1:26 | require ... ument") |
45
| document | tst.js:3:1:3:15 | window.document |
56
| document | tst.js:5:1:5:13 | self.document |
67
| document | tst.js:6:1:6:19 | globalThis.document |
8+
| document | tst.js:7:1:7:8 | document |
79
| foo | tst3.js:4:1:4:5 | w.foo |
810
| global | tst2.js:7:1:7:6 | global |
911
| global | tst2.js:8:1:8:6 | global |
1012
| globalThis | tst.js:6:1:6:10 | globalThis |
1113
| goog | tst3.js:1:1:1:4 | goog |
1214
| goog | tst3.js:3:9:3:12 | goog |
15+
| history | tst4.js:1:1:1:46 | require ... history |
16+
| history | tst.js:7:1:7:28 | documen ... history |
1317
| self | tst.js:5:1:5:4 | self |
1418
| setTimeout | tst2.js:5:1:5:12 | g.setTimeout |
1519
| window | tst2.js:3:1:3:24 | require ... indow") |

javascript/ql/test/library-tests/Nodes/tst.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ window.document;
44
window.window.document;
55
self.document;
66
globalThis.document;
7+
document.defaultView.history;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("global/document").defaultView.history;

0 commit comments

Comments
 (0)