Merge pull request #767 from esben-semmle/js/unknown-bound-event-handler-receiver

Approved by xiemaisi
This commit is contained in:
semmle-qlci
2019-01-16 08:36:11 +00:00
committed by GitHub
3 changed files with 31 additions and 1 deletions

View File

@@ -18,7 +18,15 @@ private predicate isBoundInMethod(MethodDeclaration method) {
bindingMethod.getDeclaringClass() = method.getDeclaringClass() and
not bindingMethod.isStatic() and
thiz.getBinder().getAstNode() = bindingMethod.getBody()
|
|
exists (DataFlow::MethodCallNode bind, DataFlow::PropWrite w |
// this[x] = <expr>.bind(...)
w = thiz.getAPropertyWrite() and
not exists(w.getPropertyName()) and
bind.getMethodName() = "bind" and
bind.flowsTo(w.getRhs())
)
or
// require("auto-bind")(this)
thiz.flowsTo(DataFlow::moduleImport("auto-bind").getACall().getArgument(0))
or

View File

@@ -134,4 +134,25 @@ class Component2 extends React.Component {
}
}
class Component3 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughIterator}/> // OK
</div>
}
constructor(props) {
super(props);
Object.getOwnPropertyNames( Component3.prototype )
.filter( prop => typeof this[ prop ] === 'function' )
.forEach( prop => ( this[ prop ] = this[ prop ].bind( this ) ) );
}
bound_throughIterator() {
this.setState({ });
}
}
// semmle-extractor-options: --experimental