Skip to content

Commit f23c603

Browse files
committed
JS: Restrict domValueRef to known DOM property names
1 parent bb2b7fb commit f23c603

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,25 @@ module DOM {
291291
*/
292292
abstract class Range extends DataFlow::Node { }
293293

294+
private string getADomPropertyName() {
295+
exists(ExternalInstanceMemberDecl decl |
296+
result = decl.getName() and
297+
isDomRootType(decl.getDeclaringType().getASupertype*())
298+
)
299+
}
300+
294301
private class DefaultRange extends Range {
295302
DefaultRange() {
296303
this.asExpr().(VarAccess).getVariable() instanceof DOMGlobalVariable
297304
or
298-
this = domValueRef().getAPropertyRead()
305+
exists(DataFlow::PropRead read |
306+
this = read and
307+
read = domValueRef().getAPropertyRead()
308+
|
309+
not read.mayHavePropertyName(_)
310+
or
311+
read.mayHavePropertyName(getADomPropertyName())
312+
)
299313
or
300314
this = domElementCreationOrQuery()
301315
or

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@ test_locationRef
44
| customization.js:3:3:3:14 | doc.location |
55
test_domValueRef
66
| customization.js:4:3:4:28 | doc.get ... 'test') |
7-
| tst.js:45:8:45:7 | this |
8-
| tst.js:46:7:46:12 | this.x |
97
| tst.js:49:3:49:8 | window |
108
| tst.js:50:3:50:8 | window |
11-
| tst.js:50:3:50:14 | window.myApp |
12-
| tst.js:50:3:50:18 | window.myApp.foo |

0 commit comments

Comments
 (0)