Skip to content

Commit 8de8696

Browse files
committed
model that this in a jQuery plugin is a jQuery object
1 parent da32926 commit 8de8696

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • javascript/ql/src/semmle/javascript/frameworks

javascript/ql/src/semmle/javascript/frameworks/jQuery.qll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,40 @@ module JQuery {
496496
hasUnderlyingType("jQuery")
497497
}
498498
}
499+
500+
/**
501+
* Gets a node that is written to `$.fn[something]`.
502+
* JQuery plugins are registered this way.
503+
*/
504+
private DataFlow::Node getAFnWrite() {
505+
exists(DataFlow::PropWrite write, DataFlow::PropRead jQueryFN |
506+
write.getBase() = jQueryFN and
507+
jQueryFN.getBase().getALocalSource() = JQuery::dollar() and
508+
jQueryFN.getPropertyName() = "fn" and
509+
result = write.getRhs()
510+
)
511+
}
512+
513+
/**
514+
* Gets a node that is backtracked from a node written to `$.fn[something]`.
515+
*/
516+
private DataFlow::SourceNode writtenToJqueryFN(DataFlow::TypeBackTracker t) {
517+
t.start() and result = getAFnWrite().getALocalSource()
518+
or
519+
exists(DataFlow::TypeBackTracker t2 | result = writtenToJqueryFN(t2).backtrack(t2, t))
520+
}
521+
522+
/**
523+
* A `this` node in a JQuery plugin function, which is a JQuery object.
524+
*/
525+
private class JQueryPluginThisObject extends Range {
526+
JQueryPluginThisObject() {
527+
this =
528+
DataFlow::thisNode(writtenToJqueryFN(DataFlow::TypeBackTracker::end())
529+
.(DataFlow::FunctionNode)
530+
.getFunction())
531+
}
532+
}
499533
}
500534

501535
/** A source of jQuery objects from the AST-based `JQueryObject` class. */

0 commit comments

Comments
 (0)