Skip to content

Commit ee43db1

Browse files
committed
slightly expand the $().each model
1 parent 448ed15 commit ee43db1

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ module DOM {
308308
or
309309
// A `this` node from a callback given to a `$().each(callback)` call.
310310
// purposely not using JQuery::MethodCall to avoid `jquery.each()`.
311-
this = DataFlow::thisNode(JQuery::objectRef().getAMethodCall("each").getCallback(0).getFunction())
311+
exists(DataFlow::CallNode eachCall | eachCall = JQuery::objectRef().getAMethodCall("each") |
312+
this = DataFlow::thisNode(eachCall.getCallback(0).getFunction()) or
313+
this = eachCall.getABoundCallbackParameter(0, 1)
314+
)
312315
}
313316
}
314317
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ nodes
355355
| tst.js:362:16:362:21 | target |
356356
| tst.js:366:21:366:26 | target |
357357
| tst.js:366:21:366:26 | target |
358+
| tst.js:369:18:369:23 | target |
359+
| tst.js:369:18:369:23 | target |
358360
| typeahead.js:20:13:20:45 | target |
359361
| typeahead.js:20:22:20:38 | document.location |
360362
| typeahead.js:20:22:20:38 | document.location |
@@ -682,6 +684,8 @@ edges
682684
| tst.js:361:10:361:42 | target | tst.js:362:16:362:21 | target |
683685
| tst.js:361:10:361:42 | target | tst.js:366:21:366:26 | target |
684686
| tst.js:361:10:361:42 | target | tst.js:366:21:366:26 | target |
687+
| tst.js:361:10:361:42 | target | tst.js:369:18:369:23 | target |
688+
| tst.js:361:10:361:42 | target | tst.js:369:18:369:23 | target |
685689
| tst.js:361:19:361:35 | document.location | tst.js:361:19:361:42 | documen ... .search |
686690
| tst.js:361:19:361:35 | document.location | tst.js:361:19:361:42 | documen ... .search |
687691
| tst.js:361:19:361:42 | documen ... .search | tst.js:361:10:361:42 | target |
@@ -789,6 +793,7 @@ edges
789793
| tst.js:355:12:355:17 | target | tst.js:354:16:354:32 | document.location | tst.js:355:12:355:17 | target | Cross-site scripting vulnerability due to $@. | tst.js:354:16:354:32 | document.location | user-provided value |
790794
| tst.js:362:16:362:21 | target | tst.js:361:19:361:35 | document.location | tst.js:362:16:362:21 | target | Cross-site scripting vulnerability due to $@. | tst.js:361:19:361:35 | document.location | user-provided value |
791795
| tst.js:366:21:366:26 | target | tst.js:361:19:361:35 | document.location | tst.js:366:21:366:26 | target | Cross-site scripting vulnerability due to $@. | tst.js:361:19:361:35 | document.location | user-provided value |
796+
| tst.js:369:18:369:23 | target | tst.js:361:19:361:35 | document.location | tst.js:369:18:369:23 | target | Cross-site scripting vulnerability due to $@. | tst.js:361:19:361:35 | document.location | user-provided value |
792797
| typeahead.js:25:18:25:20 | val | typeahead.js:20:22:20:38 | document.location | typeahead.js:25:18:25:20 | val | Cross-site scripting vulnerability due to $@. | typeahead.js:20:22:20:38 | document.location | user-provided value |
793798
| v-html.vue:2:8:2:23 | v-html=tainted | v-html.vue:6:42:6:58 | document.location | v-html.vue:2:8:2:23 | v-html=tainted | Cross-site scripting vulnerability due to $@. | v-html.vue:6:42:6:58 | document.location | user-provided value |
794799
| winjs.js:3:43:3:49 | tainted | winjs.js:2:17:2:33 | document.location | winjs.js:3:43:3:49 | tainted | Cross-site scripting vulnerability due to $@. | winjs.js:2:17:2:33 | document.location | user-provided value |

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ nodes
355355
| tst.js:362:16:362:21 | target |
356356
| tst.js:366:21:366:26 | target |
357357
| tst.js:366:21:366:26 | target |
358+
| tst.js:369:18:369:23 | target |
359+
| tst.js:369:18:369:23 | target |
358360
| typeahead.js:9:28:9:30 | loc |
359361
| typeahead.js:9:28:9:30 | loc |
360362
| typeahead.js:10:16:10:18 | loc |
@@ -686,6 +688,8 @@ edges
686688
| tst.js:361:10:361:42 | target | tst.js:362:16:362:21 | target |
687689
| tst.js:361:10:361:42 | target | tst.js:366:21:366:26 | target |
688690
| tst.js:361:10:361:42 | target | tst.js:366:21:366:26 | target |
691+
| tst.js:361:10:361:42 | target | tst.js:369:18:369:23 | target |
692+
| tst.js:361:10:361:42 | target | tst.js:369:18:369:23 | target |
689693
| tst.js:361:19:361:35 | document.location | tst.js:361:19:361:42 | documen ... .search |
690694
| tst.js:361:19:361:35 | document.location | tst.js:361:19:361:42 | documen ... .search |
691695
| tst.js:361:19:361:42 | documen ... .search | tst.js:361:10:361:42 | target |

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,11 @@ function thisNodes() {
362362
this.html(target); // NOT OK. (this is a jQuery object)
363363
this.innerHTML = target // OK. (this is a jQuery object)
364364

365-
this.each(function () {
365+
this.each(function (i, e) {
366366
this.innerHTML = target; // NOT OK. (this is a DOM-node);
367367
this.html(target); // OK. (this is a DOM-node);
368+
369+
e.innerHTML = target; // NOT OK.
368370
});
369371
}
370372
$.fn[pluginName] = myPlugin;

0 commit comments

Comments
 (0)