Skip to content

Commit 89cba08

Browse files
authored
Merge pull request #1892 from asger-semmle/event-handler-sink
Approved by esben-semmle
2 parents 28fece0 + b6690bb commit 89cba08

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

change-notes/1.23/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| **Query** | **Expected impact** | **Change** |
1919
|--------------------------------|------------------------------|---------------------------------------------------------------------------|
2020
| Client-side cross-site scripting (`js/xss`) | More results | More potential vulnerabilities involving functions that manipulate DOM attributes are now recognized. |
21+
| Code injection (`js/code-injection`) | More results | More potential vulnerabilities involving functions that manipulate DOM event handler attributes are now recognized. |
2122
| Prototype pollution (`js/prototype-pollution`) | More results | The query now highlights vulnerable uses of jQuery and Angular, and the results are shown on LGTM by default. |
2223

2324
## Changes to QL libraries

javascript/ql/src/semmle/javascript/security/dataflow/CodeInjectionCustomizations.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,18 @@ module CodeInjection {
101101
)
102102
}
103103
}
104+
105+
/**
106+
* An event handler attribute as a code injection sink.
107+
*/
108+
class EventHandlerAttributeSink extends Sink {
109+
EventHandlerAttributeSink() {
110+
exists(DOM::AttributeDefinition def |
111+
def.getName().regexpMatch("(?i)on.+") and
112+
this = def.getValueNode() and
113+
// JSX event handlers are functions, not strings
114+
not def instanceof JSXAttribute
115+
)
116+
}
117+
}
104118
}

javascript/ql/test/query-tests/Security/CWE-094/CodeInjection/CodeInjection.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ nodes
5555
| tst.js:23:11:23:27 | document.location |
5656
| tst.js:23:11:23:32 | documen ... on.hash |
5757
| tst.js:23:11:23:45 | documen ... ring(1) |
58+
| tst.js:26:26:26:33 | location |
59+
| tst.js:26:26:26:40 | location.search |
60+
| tst.js:26:26:26:53 | locatio ... ring(1) |
5861
edges
5962
| angularjs.js:10:22:10:29 | location | angularjs.js:10:22:10:36 | location.search |
6063
| angularjs.js:13:23:13:30 | location | angularjs.js:13:23:13:37 | location.search |
@@ -93,6 +96,8 @@ edges
9396
| tst.js:23:11:23:27 | document.location | tst.js:23:11:23:32 | documen ... on.hash |
9497
| tst.js:23:11:23:32 | documen ... on.hash | tst.js:23:11:23:45 | documen ... ring(1) |
9598
| tst.js:23:11:23:45 | documen ... ring(1) | tst.js:23:6:23:46 | atob(do ... ing(1)) |
99+
| tst.js:26:26:26:33 | location | tst.js:26:26:26:40 | location.search |
100+
| tst.js:26:26:26:40 | location.search | tst.js:26:26:26:53 | locatio ... ring(1) |
96101
#select
97102
| angularjs.js:10:22:10:36 | location.search | angularjs.js:10:22:10:29 | location | angularjs.js:10:22:10:36 | location.search | $@ flows to here and is interpreted as code. | angularjs.js:10:22:10:29 | location | User-provided value |
98103
| angularjs.js:13:23:13:37 | location.search | angularjs.js:13:23:13:30 | location | angularjs.js:13:23:13:37 | location.search | $@ flows to here and is interpreted as code. | angularjs.js:13:23:13:30 | location | User-provided value |
@@ -120,3 +125,4 @@ edges
120125
| tst.js:17:21:17:42 | documen ... on.hash | tst.js:17:21:17:37 | document.location | tst.js:17:21:17:42 | documen ... on.hash | $@ flows to here and is interpreted as code. | tst.js:17:21:17:37 | document.location | User-provided value |
121126
| tst.js:20:30:20:51 | documen ... on.hash | tst.js:20:30:20:46 | document.location | tst.js:20:30:20:51 | documen ... on.hash | $@ flows to here and is interpreted as code. | tst.js:20:30:20:46 | document.location | User-provided value |
122127
| tst.js:23:6:23:46 | atob(do ... ing(1)) | tst.js:23:11:23:27 | document.location | tst.js:23:6:23:46 | atob(do ... ing(1)) | $@ flows to here and is interpreted as code. | tst.js:23:11:23:27 | document.location | User-provided value |
128+
| tst.js:26:26:26:53 | locatio ... ring(1) | tst.js:26:26:26:33 | location | tst.js:26:26:26:53 | locatio ... ring(1) | $@ flows to here and is interpreted as code. | tst.js:26:26:26:33 | location | User-provided value |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ WebAssembly.compileStreaming(document.location.hash);
2121

2222
// NOT OK
2323
eval(atob(document.location.hash.substring(1)));
24+
25+
// NOT OK
26+
$('<a>').attr("onclick", location.search.substring(1));

0 commit comments

Comments
 (0)