@@ -256,6 +256,27 @@ private module FlaskModel {
256256 /** Gets a reference to the `flask.views.View` class or any subclass. */
257257 DataFlow:: Node subclassRef ( ) { result = subclassRef ( DataFlow:: TypeTracker:: end ( ) ) }
258258 }
259+
260+ /**
261+ * Provides models for the `flask.views.MethodView` class and subclasses.
262+ *
263+ * See https://flask.palletsprojects.com/en/1.1.x/views/#method-based-dispatching.
264+ */
265+ module MethodView {
266+ /** Gets a reference to the `flask.views.View` class or any subclass. */
267+ private DataFlow:: Node subclassRef ( DataFlow:: TypeTracker t ) {
268+ t .start ( ) and
269+ result = views_attr ( "MethodView" )
270+ or
271+ // subclasses in project code
272+ result .asExpr ( ) .( ClassExpr ) .getABase ( ) = subclassRef ( t .continue ( ) ) .asExpr ( )
273+ or
274+ exists ( DataFlow:: TypeTracker t2 | result = subclassRef ( t2 ) .track ( t2 , t ) )
275+ }
276+
277+ /** Gets a reference to the `flask.views.View` class or any subclass. */
278+ DataFlow:: Node subclassRef ( ) { result = subclassRef ( DataFlow:: TypeTracker:: end ( ) ) }
279+ }
259280 }
260281 }
261282
@@ -377,6 +398,19 @@ private module FlaskModel {
377398 DataFlow:: Node asViewResult ( ) { result = asViewResult ( DataFlow:: TypeTracker:: end ( ) ) }
378399 }
379400
401+ class FlaskMethodViewClassDef extends FlaskViewClassDef {
402+ FlaskMethodViewClassDef ( ) { this .getABase ( ) = flask:: views:: MethodView:: subclassRef ( ) .asExpr ( ) }
403+
404+ override Function getARequestHandler ( ) {
405+ result = super .getARequestHandler ( )
406+ or
407+ // TODO: This doesn't handle attribute assignment. Should be OK, but analysis is not as complete as with
408+ // points-to and `.lookup`, which would handle `post = my_post_handler` inside class def
409+ result = this .getAMethod ( ) and
410+ result .getName ( ) = HTTP:: httpVerbLower ( )
411+ }
412+ }
413+
380414 private string werkzeug_rule_re ( ) {
381415 // since flask uses werkzeug internally, we are using its routing rules from
382416 // https://github.com/pallets/werkzeug/blob/4dc8d6ab840d4b78cbd5789cef91b01e3bde01d5/src/werkzeug/routing.py#L138-L151
0 commit comments