File tree Expand file tree Collapse file tree
javascript/ql/src/semmle/javascript/frameworks Expand file tree Collapse file tree Original file line number Diff line number Diff 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. */
You can’t perform that action at this time.
0 commit comments