Skip to content

Commit 30cc914

Browse files
committed
javascript: Add support for document.defaultView in global variable references
Updated the data flow analysis to include `document.defaultView` as a source node for global variable references. Added a new test file `tst4.js` and updated existing tests to verify the inclusion of `defaultView` and its properties in the expected results.
1 parent fabcd04 commit 30cc914

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ DataFlow::SourceNode globalObjectRef() {
383383
// DOM
384384
result = globalVariable("window")
385385
or
386+
// DOM alias via `document.defaultView`
387+
result = globalVariable("document").getAPropertyReference("defaultView")
388+
or
386389
// Node.js
387390
result = globalVariable("global")
388391
or

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)