Skip to content

Commit 2e252ba

Browse files
author
Max Schaefer
committed
JavaScript: Learn that receivers of DOM event handlers are themselves DOM nodes.
1 parent ae2a5da commit 2e252ba

File tree

7 files changed

+51
-1
lines changed

7 files changed

+51
-1
lines changed

javascript/ql/src/semmle/javascript/DOM.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ module DOM {
353353
this = DataFlow::thisNode(eachCall.getCallback(0).getFunction()) or
354354
this = eachCall.getABoundCallbackParameter(0, 1)
355355
)
356+
or
357+
// A receiver node of an event handler on a DOM node
358+
exists(string handler | handler.matches("on%") |
359+
this = domValueRef().getAPropertySource(handler).(DataFlow::FunctionNode).getReceiver()
360+
)
361+
or
362+
this = DataFlow::thisNode(any(EventHandlerCode evt))
356363
}
357364
}
358365
}

javascript/ql/test/library-tests/DOM/Customizations.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ test_locationRef
88
test_domValueRef
99
| customization.js:4:3:4:20 | doc.getElementById |
1010
| customization.js:4:3:4:28 | doc.get ... 'test') |
11+
| event-handler-receiver.html:4:20:4:19 | this |
1112
| event-handler-receiver.js:1:1:1:23 | documen ... entById |
1213
| event-handler-receiver.js:1:1:1:32 | documen ... my-id') |
14+
| event-handler-receiver.js:1:44:1:43 | this |
15+
| event-handler-receiver.js:2:3:2:17 | this.parentNode |
1316
| nameditems.js:1:1:1:23 | documen ... entById |
1417
| nameditems.js:1:1:1:30 | documen ... ('foo') |
1518
| nameditems.js:1:1:2:19 | documen ... em('x') |

javascript/ql/test/library-tests/DOM/externs/externs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ function WorkerGlobalScope() {}
1818

1919
/** @type {WorkerLocation} */
2020
WorkerGlobalScope.prototype.location;
21+
22+
/**
23+
* @constructor
24+
* @implements {EventTarget}
25+
*/
26+
function Node() {}
27+
28+
/**
29+
* @type {Node}
30+
*/
31+
Node.prototype.parentNode;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
| query-tests/Security/CWE-079/DomBasedXss/event-handler-receiver.js:2 | expected an alert, but found none | NOT OK | |

javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/Xss.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ nodes
118118
| dates.js:18:31:18:66 | `Time i ... aint)}` |
119119
| dates.js:18:42:18:64 | datefor ... taint) |
120120
| dates.js:18:59:18:63 | taint |
121+
| event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
122+
| event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
123+
| event-handler-receiver.js:2:49:2:56 | location |
124+
| event-handler-receiver.js:2:49:2:56 | location |
125+
| event-handler-receiver.js:2:49:2:61 | location.href |
121126
| express.js:7:15:7:33 | req.param("wobble") |
122127
| express.js:7:15:7:33 | req.param("wobble") |
123128
| express.js:7:15:7:33 | req.param("wobble") |
@@ -751,6 +756,10 @@ edges
751756
| dates.js:18:42:18:64 | datefor ... taint) | dates.js:18:31:18:66 | `Time i ... aint)}` |
752757
| dates.js:18:42:18:64 | datefor ... taint) | dates.js:18:31:18:66 | `Time i ... aint)}` |
753758
| dates.js:18:59:18:63 | taint | dates.js:18:42:18:64 | datefor ... taint) |
759+
| event-handler-receiver.js:2:49:2:56 | location | event-handler-receiver.js:2:49:2:61 | location.href |
760+
| event-handler-receiver.js:2:49:2:56 | location | event-handler-receiver.js:2:49:2:61 | location.href |
761+
| event-handler-receiver.js:2:49:2:61 | location.href | event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
762+
| event-handler-receiver.js:2:49:2:61 | location.href | event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
754763
| express.js:7:15:7:33 | req.param("wobble") | express.js:7:15:7:33 | req.param("wobble") |
755764
| jquery.js:2:7:2:40 | tainted | jquery.js:7:20:7:26 | tainted |
756765
| jquery.js:2:7:2:40 | tainted | jquery.js:8:28:8:34 | tainted |
@@ -1255,6 +1264,7 @@ edges
12551264
| dates.js:13:31:13:72 | `Time i ... time)}` | dates.js:9:36:9:50 | window.location | dates.js:13:31:13:72 | `Time i ... time)}` | Cross-site scripting vulnerability due to $@. | dates.js:9:36:9:50 | window.location | user-provided value |
12561265
| dates.js:16:31:16:69 | `Time i ... aint)}` | dates.js:9:36:9:50 | window.location | dates.js:16:31:16:69 | `Time i ... aint)}` | Cross-site scripting vulnerability due to $@. | dates.js:9:36:9:50 | window.location | user-provided value |
12571266
| dates.js:18:31:18:66 | `Time i ... aint)}` | dates.js:9:36:9:50 | window.location | dates.js:18:31:18:66 | `Time i ... aint)}` | Cross-site scripting vulnerability due to $@. | dates.js:9:36:9:50 | window.location | user-provided value |
1267+
| event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' | event-handler-receiver.js:2:49:2:56 | location | event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' | Cross-site scripting vulnerability due to $@. | event-handler-receiver.js:2:49:2:56 | location | user-provided value |
12581268
| express.js:7:15:7:33 | req.param("wobble") | express.js:7:15:7:33 | req.param("wobble") | express.js:7:15:7:33 | req.param("wobble") | Cross-site scripting vulnerability due to $@. | express.js:7:15:7:33 | req.param("wobble") | user-provided value |
12591269
| jquery.js:7:5:7:34 | "<div i ... + "\\">" | jquery.js:2:17:2:40 | documen ... .search | jquery.js:7:5:7:34 | "<div i ... + "\\">" | Cross-site scripting vulnerability due to $@. | jquery.js:2:17:2:40 | documen ... .search | user-provided value |
12601270
| jquery.js:8:18:8:34 | "XSS: " + tainted | jquery.js:2:17:2:33 | document.location | jquery.js:8:18:8:34 | "XSS: " + tainted | Cross-site scripting vulnerability due to $@. | jquery.js:2:17:2:33 | document.location | user-provided value |

javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/XssWithAdditionalSources.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ nodes
118118
| dates.js:18:31:18:66 | `Time i ... aint)}` |
119119
| dates.js:18:42:18:64 | datefor ... taint) |
120120
| dates.js:18:59:18:63 | taint |
121+
| event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
122+
| event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
123+
| event-handler-receiver.js:2:49:2:56 | location |
124+
| event-handler-receiver.js:2:49:2:56 | location |
125+
| event-handler-receiver.js:2:49:2:61 | location.href |
121126
| express.js:7:15:7:33 | req.param("wobble") |
122127
| express.js:7:15:7:33 | req.param("wobble") |
123128
| express.js:7:15:7:33 | req.param("wobble") |
@@ -762,6 +767,10 @@ edges
762767
| dates.js:18:42:18:64 | datefor ... taint) | dates.js:18:31:18:66 | `Time i ... aint)}` |
763768
| dates.js:18:42:18:64 | datefor ... taint) | dates.js:18:31:18:66 | `Time i ... aint)}` |
764769
| dates.js:18:59:18:63 | taint | dates.js:18:42:18:64 | datefor ... taint) |
770+
| event-handler-receiver.js:2:49:2:56 | location | event-handler-receiver.js:2:49:2:61 | location.href |
771+
| event-handler-receiver.js:2:49:2:56 | location | event-handler-receiver.js:2:49:2:61 | location.href |
772+
| event-handler-receiver.js:2:49:2:61 | location.href | event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
773+
| event-handler-receiver.js:2:49:2:61 | location.href | event-handler-receiver.js:2:31:2:83 | '<h2><a ... ></h2>' |
765774
| express.js:7:15:7:33 | req.param("wobble") | express.js:7:15:7:33 | req.param("wobble") |
766775
| jquery.js:2:7:2:40 | tainted | jquery.js:7:20:7:26 | tainted |
767776
| jquery.js:2:7:2:40 | tainted | jquery.js:8:28:8:34 | tainted |

javascript/ql/test/query-tests/Security/CWE-079/DomBasedXss/externs.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ DomObjectStub.prototype.value;
4646
* @type {!DomObjectStub}
4747
*/
4848
var document;
49+
50+
/**
51+
* @constructor
52+
* @implements {EventTarget}
53+
*/
54+
function Node() {}
55+
56+
/**
57+
* @type {Node}
58+
*/
59+
Node.prototype.parentNode;

0 commit comments

Comments
 (0)