Skip to content

Commit 67b38ed

Browse files
committed
correctly weed out benign calls inside attributes
1 parent b0fecbc commit 67b38ed

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

javascript/ql/src/Statements/UseOfReturnlessFunction.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ predicate benignContext(Expr e) {
4545

4646
or
4747
// weeds out calls inside HTML-attributes.
48-
e.getParent() instanceof CodeInAttribute or
48+
e.getParent().(ExprStmt).getParent() instanceof CodeInAttribute or
4949
// and JSX-attributes.
5050
e = any(JSXAttribute attr).getValue() or
5151

javascript/ql/test/query-tests/Statements/UseOfReturnlessFunction/UseOfReturnlessFunction.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| tst.html:19:28:19:40 | addHandlers() | the $@ does not return anything, yet the return value is used. | tst.html:5:7:12:7 | functio ... } | function addHandlers |
12
| tst.js:20:17:20:33 | onlySideEffects() | the $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | function onlySideEffects |
23
| tst.js:24:13:24:29 | onlySideEffects() | the $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | function onlySideEffects |
34
| tst.js:30:20:30:36 | onlySideEffects() | the $@ does not return anything, yet the return value is used. | tst.js:11:5:13:5 | functio ... )\\n } | function onlySideEffects |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
function addHandlers () {
6+
const cdoc = document.getElementById('container').contentDocument;
7+
if (cdoc) {
8+
const scriptelm = cdoc.createElement('script');
9+
scriptelm.src = '../handlers.js';
10+
cdoc.getElementsByTagName('head')[0].appendChild(scriptelm);
11+
}
12+
}
13+
</script>
14+
</head>
15+
<body>
16+
<object id="container" data="editor/svg-editor.html" onload="addHandlers()"></object>
17+
<a href="javascript:addHandlers()">Foo</a>
18+
<div onclick="addHandlers()">Click me</div>
19+
<div onclick="console.log(addHandlers() + 3)">Click me</div> <!-- NOT OK! -->
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)