Skip to content

Commit ab07420

Browse files
committed
JS: Enhance isDomProperty to check for getAPropertyRead on DOM nodes
1 parent db9a247 commit ab07420

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

javascript/ql/lib/Expressions/DOMProperties.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ predicate isDomProperty(string p) {
1010
exists(ExternalMemberDecl emd | emd.getName() = p |
1111
isDomRootType(emd.getDeclaringType().getASupertype*())
1212
)
13+
or
14+
exists(DataFlow::SourceNode domNode | isDomNode(domNode) |
15+
p = domNode.getAPropertyRead().getPropertyName()
16+
)
1317
}

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| dom.js:5:3:5:18 | box.offsetHeight | This expression has no effect. |
2-
| dom.js:11:5:11:40 | documen ... ntWidth | This expression has no effect. |
31
| try.js:22:9:22:26 | x.ordinaryProperty | This expression has no effect. |
42
| tst2.js:2:4:2:4 | 0 | This expression has no effect. |
53
| tst.js:3:1:3:2 | 23 | This expression has no effect. |

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/dom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ function f() {
22
const box = document.getElementById('box');
33
box.classList.remove('animate');
44
// Force a reflow by reading layout property (side effect!)
5-
box.offsetHeight; // $SPURIOUS:Alert
5+
box.offsetHeight;
66

77
try {
88
console.log("Hello, world!");
99
} catch (e) {
1010
// Reading this property also forces layout
11-
document.documentElement.clientWidth; // $SPURIOUS:Alert
11+
document.documentElement.clientWidth;
1212
}
1313
}

0 commit comments

Comments
 (0)